Thursday, April 12, 2012

Variable In Link Redirect JavaScript

I want to make something so that a variable is shown in a redirect, but I can't seem to figure out how. I want the page to redirect to google.com/'name' (the variable) for my website, but whatever I try doesn't seem to work. This may seem a little confusing, if so, leave a comment, don't answer. Here's the code:



<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","Harry Potter");
if (name!=null && name!="")
{
alert("Hi + name + !");
window.top.location.replace("http://www.google.com/" + name ");
}
}
</script>
</head>
<body>
<input type="button" onclick="show_prompt()" value="Show prompt box" />
</body>
</html>




No comments:

Post a Comment