<head>
<script type="text/javascript">
window.location.href='http://www.google.com';
</script>
</head>
<body>
</body>
</html>
the above program is working but when I change the program using onclick event it didn't work.But the below code is perfectly valid when you just put alert box instead of window.location.href and you can check it by yourself.
<html>
<head>
<script type="text/javascript">
function hello()
{
window.location.href='http://www.google.com';
}
</script>
</head>
<body>
<form>
<input type="submit" id="intro" onclick="hello()" value="Reload the page" />
</form>
</body>
</html>
then one of my friend named whosaidwhat figured it out it is due to type submit and so he advised to change it to button and i tried it .Yes it worked.
<html>
<head>
<script type="text/javascript">
function hello()
{
alert("welcome");
window.location.href='http://www.google.com';
}
</script>
</head>
<body>
<form>
<input type="button" id="intro" onclick="hello()" value="Reload the page" />
</form>
</body>
</html>
when I asked the reason whosaidwhat bro told as follows
"I cannot really give you detailed information on the inner workings of how web browsers handle javascript on submit buttons. I imagine that because it is a submit button it will be submitting the forms data to another page, and would not be expecting a URL redirect as it would break the forms submission. The browser is probably set up to ignore the redirect if the type of control that calls the javascript is of type 'submit'. Sorry I cant offer more detail than this."
Responses
0 Respones to "small program (url) related to javascript"
Post a Comment