JavaScript正文onunload不起作用

编程入门 行业动态 更新时间:2024-10-11 21:21:49
本文介绍了JavaScript正文onunload不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好我有以下代码: pre $ function redirect(){ window.location.href =' logged_out_chat.php; }

...在我的标题和以下正文标记中:

< body onunload =javascript:redirect();>

...当我在一台笔记本电脑上试用时,它会重定向,因为它应该是(当你点击任何链接),但在我的其他笔记本电脑,台式机和笔记本电脑上,它会忽略重定向并转到您点击的任何链接。 我在这上面花了几个小时......都有相同的浏览器。我想知道是否有其他方式可以在用户点击链接时重定向。

期望会发生?

当我在浏览器中关闭您的页面时您可以将我重定向到您喜欢的页面?

这将重新开始安全和用户控制。当我关闭它时,你应该无法干扰页面。

士气不会依赖 onunload 做任何不重要的事情。

Hi I have the following code:

function redirect(){ window.location.href='logged_out_chat.php'; }

...in my header and the following body tag:

<body onunload="javascript:redirect();">

...when i try this on one laptop, it redirects as it is supposed to (when you click on any link), but on my other laptop, desktop and notebook it ignores the redirect and goes to any link you click on. I have spent hours on this...all have the same browser. I was wondering if there is an alternative way i could redirect the user when they click on a link etc.

解决方案

What do you expect would happen?

When I close your page in my browser you get to redirect me to a page of your liking?

This goes againts security and user control. You shouldn't be able to interfere with the page when I close it.

The morale is don't rely on onunload to do anything non-trivial.

更多推荐

JavaScript正文onunload不起作用

本文发布于:2023-11-26 20:27:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   正文   JavaScript   onunload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!