If you're looking to create a link that automatically opens when a webpage loads, there's an easy solution. By creating an HTML script, you can set up a link that opens as soon as someone visits your website. In this article, we'll show you how to create an HTML script to open a link on page load.

You can create an HTML script to open a link on page load using the Html codding
can help you with that. Here is an article about onload link open HTML coding:


HTML script to open a link when page loading of website


 On-page loading  Link Open Script for website

Onload links are a way to open a link when a page loads. This can be incredibly useful for redirecting users from one page to another, or for displaying important information on the page.

In HTML, onload links are embedded in the body tag. This tag contains the instructions for loading the page. It can be used to set the background color, to set a link, or to set an onload link. To set an onload link, you need to add the onload attribute to the body tag.

The onload attribute takes a script as a value. This script can be any type of JavaScript code, including a function. It is a good practice to use a function as the value of the onload attribute. This way, the code will only run when the page loads, instead of running every time something else is run on the page.

When the page loads, the onload link will execute the script. This script can be used to open a specific link. For example, if you have a link to a landing page on your website, you can set the onload attribute to open this link when the page loads.

The onload link can also be used to open a new tab. This can be done by adding the target attribute to the link. For example, if you want to open a new Window

Step 1: Create a Link

The first step is to create the link that you want to open when the page loads. This can be any link that you want, such as a blog post, a video, or a product page. Simply copy the URL of the page you want to link to.


Step 2: Open Your HTML Editor

Next, open your HTML editor. This could be a program like Dreamweaver, or a simple text editor like Notepad. Once you have your editor open, create a new HTML file.


Step 3: Add Your Script

 On-page loading  Link Open Script for website

In the body of your HTML file, add the following script:

<script type="text/javascript">

    window.onload = function() {

        window.location.href = "http://www.yourlink.com";

    }

</script>

In this script, we are using JavaScript to open the link when the page loads. The window.onload function tells the browser to run the script as soon as the page loads. The window.location.href sets the URL of the link that you want to open.


Step 4: Save and Upload

Once you have added your script, save your HTML file and upload it to your website. Be sure to test the link to make sure that it opens properly.


By following these simple steps, you can create an HTML script to open a link on page load. This can be a great way to drive traffic to specific pages on your website, or to showcase your latest content to your visitors. As always, be sure to test your script thoroughly before publishing it live on your website.


Open Link in a New Window:

If you want the link to open in a new window instead of the current window, you can modify the script like this:

<script type="text/javascript">

    window.onload = function() {

        window.open("http://www.yourlink.com", "_blank");

    }

</script>

In this script, the window.open() function is used to open the link in a new window. The second parameter "_blank" tells the browser to open the link in a new window.


Open Multiple Links on Page Load:

If you want to open multiple links on page load, you can modify the script like this:

<script type="text/javascript">

    window.onload = function() {

        window.location.href = "http://www.yourlink1.com";

        window.open("http://www.yourlink2.com", "_blank");

    }

</script>

In this script, we are opening two links. The first link is opened using window.location.href and the second link is opened in a new window using window.open().


Redirect to a Different Page:

If you want to redirect the user to a different page on your website, you can modify the script like this:

<script type="text/javascript">

    window.onload = function() {

        window.location.href = "http://www.yournewpage.com";

    }

</script>

In this script, we are using window.location.href to redirect the user to a new page on your website.


Delayed Link Opening:

If you want to delay the link opening for a few seconds after the page loads, you can modify the script like this:

<script type="text/javascript">

    window.onload = function() {

        setTimeout(function() {

            window.location.href = "http://www.yourlink.com";

        }, 5000); // 5000 milliseconds (5 seconds)

    }

</script>

In this script, we are using setTimeout() to delay the link opening for 5 seconds after the page loads.


By using these different variations of the onload link opening script, you can create a more customized and engaging experience for your website visitors.

You can create an HTML script to open a link on page load using the following code:


  <script type="text/javascript">

      window.onload = function(){

          window.location.href = "http://www.example.com/";

      }

  </script>


  • Following are some of the solutions using plain HTML and JavaScript. You may use based on your requirement and share if you have any other solution.


  • Open Link Immediately on Page Load.

<body onload="window.open('https://www.google.com/');">


  • Open link in New Tab on page load.

<body onload="window.open('https://www.google.com/', '_blank');">


  • Refresh the same URL Using meta tags.

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

  • Refresh a different URL after 5 seconds Using meta tags.

<meta http-equiv="refresh" content="5;URL='https://www.google.com/'" />

  • Open different URL in New Tab using meta tags.

<meta http-equiv="refresh" content="5;URL=javascript:window.open('https://www.google.com/', '_blank');" />

Post a Comment

Previous Post Next Post