js code for new tab

Started on the old forum in July 2018 · view the original in the archive · old links redirect here

8 replies · 131 views · started 8 years ago · 1 min read

3 participants
omshankar Junior · 17 posts #1

Hello, I want js code to open new tab on 2nd click. I have a code. On first click it opens a new tab but after 3 second a new tab automatically opens. I want to open 2nd tab also on click after 3 seconds, not automatically. Here is my code:

<script> $(window).one('click',function() { var url = "https://google.com"; window.open(url, "_blank"); setTimeout(function(){ window.open(url, "_blank")}, 3000); }) </script>
crazybrumi Super moderator Principal · 1,064 posts #2

Hello, I want js code to open new tab on 2nd click. I have a code. On first click it opens a new tab but after 3 second a new tab automatically opens. I want to open 2nd tab also on click after 3 seconds, not automatically. Here is my code:

Try the following

$(window).one('click',function() {
var url = "https://google.com";
[COLOR=#691c97]window[/COLOR].[COLOR=#693a17]open[/COLOR]([COLOR=#0b6125]url[/COLOR],[COLOR=#0b6125]'_blank'[/COLOR]);
}

Want something coded email me at sales@webnwaphost.com for a prices.

http://flagcounter.com/more/W80q

omshankar Junior · 17 posts #3

omshankar wrote: Hello, I want js code to open new tab on 2nd click. I have a code. On first click it opens a new tab but after 3 second a new tab automatically opens. I want to open 2nd tab also on click after 3 seconds, not automatically. Here is my code:

Try the following

$(window).one('click',function() {
var url = "https://google.com";
window.open(url,'_blank');
}

it opens single popup in new tab. I want 2nd popup in new tab on clicking after 3 second. It should not be opened automatically. It should be opened after clicking.

something else Fellow · 2,296 posts #4

Something like:

<script>
            var x = 1;
            $(window).on('click',function()
            {    
                if(x==2)
                {
                    var url = "https://google.com";
                    window.open(url, "_blank");
                    setTimeout(function(){ window.open(url, "_blank")}, 3000);
                }
                x++;
            })
</script>
omshankar Junior · 17 posts #5

something else wrote: Something like:

<script>
var x = 1;
$(window).on('click',function()
{
if(x==2)
{
var url = "https://google.com";
window.open(url, "_blank");
setTimeout(function(){ window.open(url, "_blank")}, 3000);
}
x++;
})
</script>

This code also opens 2nd popup automatically. 1st popup opens on clicking. but 2nd popup opens automatically. I want 2nd popup should also open on clicking after 3 seconds.

something else Fellow · 2,296 posts #6

its not clear what you are after .... Maybe this:

<script>
            var x = 1;
            $(window).on('click',function()
            {    
                if(x==1)
                {
                    var url = "https://google.com";
                    setTimeout(function(){ window.open(url, "_blank")}, 3000);
                }
                if(x==2)
                {
                    var secondUrl = "https://google.com";
                    setTimeout(function(){ window.open(secondUrl, "_blank")}, 3000);
                }
                x++;
            })
</script>

if this isn't right can you write a process list of what you would like to happen.. eg:

page loads.. first click wait 3 seconds open popup second click wait 3 seconds open second popup

omshankar Junior · 17 posts #7

Yes, This didn't work properly. Process is like this:

Page loads first click open popup (due to clicking) wait 3 seconds second click open second popup (due to second click)

Popups should not open automatically. When I click on the page then due to clicking popup should open. Like pops of adnetworks like propeller, adcash works. i.e when you click on the page then popup opens, not automatically.

Edit: Even if I wait on that page for more than 3 seconds, popup should not open automatically. When I click after 3 seconds (may be after 20 seconds) then popup should open.

something else Fellow · 2,296 posts #8

I think this is what you are after:

<script>
            var x = 0;
            $(window).on('click',function()
            {    
                if(x==0)
                {

                    var url = "https://google.com";
                    window.open(url, "_blank")
                    x++;
                    setTimeout(function(){ x++; }, 3000);
                }
                if(x==2)
                {
                    var secondUrl = "https://google.com";
                    window.open(secondUrl, "_blank");
                    x++;
                }
            })
</script>
omshankar Junior · 17 posts #9

Yes this is what I was looking for. Works perfectly. Thanks.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close