一旦用户启用了他们的javascript,你如何重定向到一个页面?

Gar*_*ett 9 javascript redirect

我想知道在浏览器中启用javascript时是否触发了某种事件(即在firefox中,工具 - >选项 - >勾选启用javascript->单击确定).我想在发生这种情况时将用户重定向到页面.有任何想法吗?

谢谢!

编辑:我已经将iframe放入页面但没有收到警报(在我启用javascript后),因此刷新一定不能正常工作.这有什么问题?

    <iframe style="display:none">
        <html>
            <head>
                <title>my iframe</title>

                <meta http-equiv="Refresh" content="5" />

                <script type="text/javascript">
                    window.parent.location.href = 'home.php';
                    alert("HELLO");
                </script>

            </head>
        </html>
    </iframe>
Run Code Online (Sandbox Code Playgroud)

oez*_*ezi 5

不是一个好的ide,但我认为它会起作用:

  • 在您的第一页上设置5(?)秒的元刷新,并且:
  • 将javascript-redirect设置为第二页(window.location.href ='...')

只要JavaScript被禁用,用户停留在第1页,其中每5秒刷新触发...如果JavaScript的被启用,在下一次刷新的JS重定向做是为了让用户获取到第2页.


rob*_*lls 3

您只能在页面加载时检测 JavaScript 是否启用/禁用。页面加载后,没有任何事件要求启用/禁用它。我能想到的唯一可能的解决方案是在主页中有一个不可见的 iframe,其中包含一个带有小元刷新的脚本,并检查 JavaScript 是否已启用 - 如果启用则重定向父(主)页面。

所以你的 iframe 将包含这样的内容:

jscheck.html

<html>
<head>
<title>my iframe</title>
<meta http-equiv="refresh" content="5">
<script type="text/javascript">
window.parent.location.href = 'js_turned_on.html';
</script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

检查器.html

<html>
<head>
<title>Form Test</title>
</head>
<body>
<iframe src="jscheck.html"></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)