Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

i was wondering if there was some sort of event triggered when javascript is enabled in a browser (ie. in firefox, tools->options->check off enable javascript-> click ok). i want to redirect a user to a page when this happens. any ideas?

Thanks!

EDIT: i've put an iframe into the page but am not getting the alert (after i enable javascript), so the refresh must not be working. what is wrong with this?

    <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>
like image 532
Garrett Avatar asked Jul 13 '10 14:07

Garrett


People also ask

How do you redirect to another page in JavaScript with get data?

To redirect to another page in JavaScript, you can use window. location. href property, window. location will also work and if you want you can use window.

Which method is used to redirect the webpage in JavaScript?

In Javascript, window. location function is used to redirect to a URL.

How do I redirect a user to another page?

To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.


2 Answers

not realy a good ide, but i think it would work:

  • set a meta-refresh of 5(?) seconds on your first page and:
  • set a javascript-redirect to your second page (window.location.href='...')

as long as javascript is disabled, the user stays on page1, where every 5 seconds the refresh is triggered... if javascript gets enabled, on the next refresh the js-redirect is done so the user gets to page2.

like image 169
oezi Avatar answered Oct 21 '22 23:10

oezi


You can only detect whether JavaScript is enabled/disabled on page load. There is no event called for it being enabled/disabled after a page has loaded. Only possible solution i can think is to have an invisible iframe in your main page containing a script with a small meta refresh and a check for whether JavaScript is enabled - if it is then redirect the parent(main) page.

so your iframe would include something like this:

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>
like image 27
robjmills Avatar answered Oct 21 '22 22:10

robjmills