I have a asp webform with a button. The OnClientClick event is wired to a javascript function.
I need this function to redirect the current page to this page.
After much reading is have tried all the following, but to no avail:
var url = "";
document.location = url; //Doesn't Work
document.location.href = url; //Doesn't Work
window.location = url; //Doesnt Work
window.location.href = url; //Doesnt Work
Any Help or advice are wele.
Ps. I am entering the JS function as my alert message pops up
I have a asp webform with a button. The OnClientClick event is wired to a javascript function.
I need this function to redirect the current page to this page.
After much reading is have tried all the following, but to no avail:
var url = "http://www.google.";
document.location = url; //Doesn't Work
document.location.href = url; //Doesn't Work
window.location = url; //Doesnt Work
window.location.href = url; //Doesnt Work
Any Help or advice are wele.
Ps. I am entering the JS function as my alert message pops up
Share Improve this question asked Mar 11, 2010 at 7:20 SetiSeekerSetiSeeker 6,6949 gold badges46 silver badges66 bronze badges 1- 2 Above code that you mentioned should work... Could you post code of event and handler for it? – Andrew Bezzub Commented Mar 11, 2010 at 7:26
4 Answers
Reset to default 1You probably have somewhere on your code a Javascript Error, that stop the execution, because as the other say, this code that you say that "doesnt work", it's work fine.
I tried this in a html page and it worked fine.
function go() { alert(); var url = "http://www.google."; document.location.href = url; //Doesn't Work }
Just look at the page source and see whether onClientClick is calling your js function
Try putting return false; after your function in the OnClientClick
e.g. OnClientClick="yourfunction();return false;"
You can try location.replace(myUrl);
, but document.location.href
should really work.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744989558a4604819.html
评论列表(0条)