admin管理员组文章数量:1386852
Trying to do a redirect with javascript using the following code (works fine in ALL browsers except IE8 and IE7):
if (confirm('Are you sure you wish to clear your basket?')) {
window.location.href = '/basket/clear';
if (navigator.userAgent.search('MSIE') > -1) alert('Your basket has been cleared.');
}
I have added in the second alert stating that the basket has been cleared so that the code works in IE. If I remove the alert then it doesn't work.
Any ideas or solutions would be greatly appreciated.
Trying to do a redirect with javascript using the following code (works fine in ALL browsers except IE8 and IE7):
if (confirm('Are you sure you wish to clear your basket?')) {
window.location.href = '/basket/clear';
if (navigator.userAgent.search('MSIE') > -1) alert('Your basket has been cleared.');
}
I have added in the second alert stating that the basket has been cleared so that the code works in IE. If I remove the alert then it doesn't work.
Any ideas or solutions would be greatly appreciated.
Share Improve this question asked Jan 2, 2011 at 14:05 ABailissABailiss 1731 gold badge2 silver badges9 bronze badges 5-
1
If it's ing from
href
of anchor tag you must also havereturn false
otherwise the link will be "processed". – user447356 Commented Jan 2, 2011 at 14:33 - @Shadow Wizard This should be an answer. I, for one, think you are correct. – Hemlock Commented Jan 2, 2011 at 14:58
- @Hemlock not sure that's the case here.. @ABailiss can you post the code invoking that JavaScript? – user447356 Commented Jan 2, 2011 at 15:15
- It was a button that called the code, not an anchor tag. Simply adding a return false; after the redirect seems to have fixed things in IE even though it is pointless returning false for a button. – ABailiss Commented Jan 10, 2011 at 18:15
-
what button exactly? If just plain
<button onclick="...">
it defaults to submit button that when clicked will submit its form. Anyway, when menting on someone else ment use@
to notify that person (one at a time) otherwise he/she won't see your ment. – user447356 Commented Jan 10, 2011 at 22:01
1 Answer
Reset to default 3try using just window.location = '/basket/clear';
also, when you change the window location you cannot expect code beyond that point to execute, such as an alert
本文标签: Javascript Redirect windowlocationhrefIEStack Overflow
版权声明:本文标题:Javascript Redirect window.location.href - IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744573439a2613477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论