-3

I am having small of daily visitor 400 per-day. I planed to create the popup ads first I created the popup ads to open in new window . It was quit irritating the visitors .

My New window popup code

var firstClick = true;
document.body.onclick = function() {
    if (firstClick) {
        window.open('popup creating website', 'poppage', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 300, top = 50');
        window.open('popup creating second website', 'poppage2', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=950, height=650, left = 200, top = 10');
        firstClick = false;
    }
}

what i planed to get is first click on the web page to open the new tab .

Thank you

Rajeev Mehta
  • 820
  • 2
  • 10
  • 32
  • 3
    possible duplicate of [Open a URL in a new tab using JavaScript](http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript) – Marty Apr 28 '15 at 05:07
  • 1
    PS if I had the choice between ads in popups or tabs and death wasn't an option I would rather popups vs clogging up all of my tabs. – Marty Apr 28 '15 at 05:10
  • 1
    @Marty Meh. I'd just block them. – jdphenix Apr 28 '15 at 05:12
  • @Marty In that page they mention like If we click on the "button or name" then only the new tab will open.. My question is based on the any where in the page first click to open a new tab . I tried nothing is working.. – Clone Roner May 02 '15 at 22:05

2 Answers2

-2

You can use target attribute to open in new tab

Example

<a href="#" target="blank">click here</a>
stanze
  • 2,456
  • 10
  • 13
-2

You need to use "target=_blank" in your hyperlink

 $(document).ready(function(){   
     $('#newtab').click(function() {   
     $(this).target = "_blank";
     window.open($(this).prop('href'));   
     return false; 
     });
  });​

<a href="link" id="newtab" >new tab</a>
krishnakumar
  • 94
  • 10
  • May i know the reason of down vote?helps me in answering other questions. – krishnakumar Apr 28 '15 at 05:11
  • You've updated the `target` attribute of an element that hasn't been referenced in the question anywhere, then used `window.open` with the `href` attribute of the same element, making your `target` value irrelevant anyway. – Marty Apr 28 '15 at 05:17