0

I want to open all banner ads on new window, or from class, example: classs .bannerad open this in new window,

I have this code but this open my page in new window not the ads, i want to open the ads in new window not my page.

<script>
$(document).ready(function(){
  var link = location.href;
  $(".bannerad").click(function(){
    window.open(link);
  });
});
</script>

before I asked this question I tried all the codes from these posts

  1. Javascript banner link open in new window

  2. window.open with target '_blank' opens a new browser window

  3. target="_blank" vs. target="_new"

so i have see more then 10 post but do not help me.

My question now is... Exist any code javascript or jQuery to force all external links and banner ads to open in the new window? Thanks.

  • Thanks for your spam that help me to mouch. –  May 29 '18 at 18:29
  • 1
    Please read [ask]. Include html sample for at least the banner ads (if it's a link can add blank target, otherwise open with js). And yes, your `link` variable is the window.location.href – yezzz May 29 '18 at 18:43

1 Answers1

0

Try to add a target=_blank to them all.

$(document).ready(function(){
  $(".bannerad").attr("target","_blank");
});
Radmation
  • 1,486
  • 1
  • 13
  • 30
  • thanks fro your help i have try and this code, but is not working! that is Google Adsense maybe that don't allow `"target","_blank"` Thanks –  May 30 '18 at 19:04
  • @Noni Perhaps or maybe they have code that strips all the target=_blank attributes that runs after your code. Also you may want to see if that is against their policies? I have not ever ran into that specific issue. – Radmation May 30 '18 at 20:59