开发者

How do I do a Javascript Redirect in asp.net

I have a asp.net 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.com";
           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 welcome.

Ps. I am开发者_开发百科 entering the JS function as my alert message pops up


You 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.com"; 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜