Skip to content Skip to sidebar Skip to footer

Open Page Automatically Using Javascript

Essentially, all I want to do is open an external web page after the current page is loaded via java script. open my page -> javascript tells browser to open external page -&g

Solution 1:

you may use this

<html>
    <head>
    <script type="text/javascript">
    function load()
    {
    window.location.href = "http://externalpage.com";

    }
    </script>
    </head>

    <body onload="load()">
    <h1>Hello World!</h1>
    </body>
    </html> 

Solution 2:

Technically you can:

location.href = "http://example.net/";

… but you should perform an HTTP redirect instead as that is more reliable, faster and better food for search engines.


Solution 3:

<html>
<head>
<script type="text/javascript">
    function load()
    {
        window.location.href = "http://externalpage.com";
    }
</script>
</head>

<body onload="load()">
   <h1>Hello World!</h1>
</body>
</html> 

Hope it should be window.location. Check the code.


Solution 4:

You can also use the "open" method to open the source file or url on a new window.

window.open("anyfile.*");

or

window.open("http://anylocation.com");

Solution 5:

<body>
<script>
document.body.innerHTML += '<a href="https://www.google.com/" style="display: none;" id="link">Link</a>';
document.getElementById("link").click();
</script>
<body>

Post a Comment for "Open Page Automatically Using Javascript"