Script Open New Tab Url For One Click

This script will open a new tab with a single click. Next click will have no effect.
The purpose of installing this script is to increase revenue from ads or increase the number of impressions from advertisers.

Blogger Template - This time the admin will share a script that works to open the url in a new tab when a visitor clicks on our web page. This script will open a new tab with a single click. Next click will have no effect. The open new tab effect only runs on the first click.

This script is widely used on several websites such as safelink web, movie web, music web and download web. The purpose of installing this script is to increase revenue from ads or increase the number of impressions from advertisers.

Here is the script:

<script>
//<![CDATA[ document .body.addEventListener( "click" , function (
) {
     var a = document .createElement( 'a' );
    a.target = "_blank" ;
    a.href = " https://domainname.com " ;
    a.click();
}, {
    once : true
});
//]]>
</script>

Please replace the text I gave in blue with the url address you want to open.

How to Install the Script

You can put this script in the html before the element </body>. For blogger users, you can install it in the html edit section or in the Javascript widget section.

Here's how to install it for blogger users:

  • Please open your blogger dashboard.
  • Select 'Themes' then select 'Edit HTML'.
  • Then find the code '</body>' and make sure the script is right above it.
  • Don't forget to change the url I gave in blue with the url you want.
  • Then select 'Save Theme'.
  • Done.

To try it, please click in any area. If successful then the first click will open a new tab with the url address you have changed before. A second click will not give any effect.

How the Script Works

First, this script will give a click event command to the entire DOM body. This means that the click effect will work if the visitor clicks on the DOM body area.

document .body .addEventListener( "click" , function () {

});

Because we only provide the 'One click' command, we must provide the event option for a single click as follows:

document .body.addEventListener( "click" , function () {

}, {
    once : true 
});

It seems that I added an event option in the form of "once: true" where this option will give the command to run with a single click.

The click effect will then execute a function to create a DOM <a> and populate some attributes such as targets and hrefs. Take a look at the script below, See the writing that I gave in green.

document.body.addEventListener("click", function () {
    var a = document.createElement('a');
    a.target = "_blank";
    a.href = "https://domain name.com";
    a.click();
}, {
    once: true
});

When the first click is made, the script will generate a DOM <a> by filling in the target and href attributes. If we illustrate, then the DOM <a> would be as follows:

<a target="_blank" href="https://namaDomain.com"></a>

Once the DOM <a> is formed, the click () function will be run which will click automatically and finally open a new tab with the url we have set before.

That's more or less how the script works. If you have any question in your mind then please comment below. Hope this article was helpful.