How do I do a Javascript Redirect in asp.net - Stack Overflow

I have a asp webform with a button. The OnClientClick event is wired to a javascript function.I need th

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
Add a ment  | 

4 Answers 4

Reset to default 1

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

相关推荐

  • How do I do a Javascript Redirect in asp.net - Stack Overflow

    I have a asp webform with a button. The OnClientClick event is wired to a javascript function.I need th

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信