簡體   English   中英

一旦用戶啟用了他們的javascript,你如何重定向到一個頁面?

[英]how do you redirect to a page as soon as a user enables their javascript?

我想知道在瀏覽器中啟用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>

不是一個好的想法,但我認為它會工作:

  • 在您的第一頁上設置5(?)秒的元刷新,並且:
  • 將javascript-redirect設置為第二頁(window.location.href ='...')

只要javascript被禁用,用戶就會停留在page1,其中每5秒觸發一次刷新...如果javascript被啟用,則在下次刷新時,js-redirect完成,以便用戶進入page2。

您只能檢測是否在頁面加載時啟用/禁用了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>

checker.html

<html>
<head>
<title>Form Test</title>
</head>
<body>
<iframe src="jscheck.html"></iframe>
</body>
</html>

你可以在你的頁面上有一個小計時器,1秒鍾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM