How do I open a new pop-up window when clicking anywhere on the page? [duplicate]

0

I want to make the visitor click anywhere on my page to open a pop-up window behind the main window that the visitor is on. So it will not see the window that was opened.

I'm using this function:

window.onload = function()
{
    document.onclick = function( e )
    {
        window.open( 'http://www.google.com.br' );
    }
}

The problem with this function is that it only opens a new tab.

I would like it to open like this function below:

function myFunction() {
     window.open("http://google.com.br", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=1, left=1, width=1, height=1");     
}

But with this function above it only opens if there is a button to click. I wanted it to open up when you click anywhere on the page. But behind the main window.

    
asked by anonymous 27.10.2015 / 02:28

1 answer

1

Put the function out of window.onload that will work.

Example:

document.onclick = function( e ){
 myFunction();
}

function myFunction() {
window.open("http://google.com.br", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=1, left=1, width=1, height=1");
}

See working at Jsfiddle

The window.onload is stripped only after all html, css, images are loaded, now if you just need the HTML (DOM) you can use without or put a $(document).ready() .

    
27.10.2015 / 03:50