Reputation: 20916
I need to redirect a page to after user clicks a alert button but its not working in javascript...
http://jsfiddle.net/wLDsE/2/
code:
$(document).ready(function(){
alert('Go to google')
document.location.href = 'http://www.google.com';
})
Upvotes: 0
Views: 1213
Reputation: 1185
You can not redirect to a different domain. It against the role of
Same Orign policy
You only redirect within same domain.
Upvotes: 1
Reputation: 8682
Your code works fine, it is just jsFiddle wont redirect. You can see a working example of it at this jsFiddle page.
Note the /show to bring it onto a single webpage
Upvotes: 1
Reputation: 16210
Your problem is specific to JSFiddle (and other demo websites which show the resulting code in a frame). These browsers prevent this behaviour inside frames, but it'll work fine in a plain old HTML page for you.
Upvotes: 3