0

I have an iframe advertisment on my site, and i want when I click it to automatically opens in another tab. But I don't really know how to do it. I am trying with that way but it isnt working:

document.getElementById("ad_frame").contentWindow.document.body.click()
4
  • what do you mean by click automatically? Commented Mar 12, 2015 at 7:54
  • If you want to open in new tab, why you are using iframe? You can use anchor tag with target="_blank" Commented Mar 12, 2015 at 8:13
  • This sound like an attempt to build up clicks on advertisement to gain more revenue, if so then you might want to make sure this isn't going to breach the agreements as you could face legal action. Example google adsense, this would be against their terms/agreements. Reason for my suspicion? Adverts/Click without them knowing how Commented Mar 12, 2015 at 8:16
  • It's 100% legal, be sure. And i can't use an anchor, because when i clicking it, i just get redirected to a picture that need to be clicked once again to be delivered to target site :\ Commented Mar 12, 2015 at 9:07

1 Answer 1

1

You can simply do it by window.open() function. Like that:

 <script language="javascript">
 window.open("http://www.ad-site.com");
 </script>

If this doesn't answer the question, please specify the question better.

Sign up to request clarification or add additional context in comments.

6 Comments

I have an iframe with link like adv-partner.com/11111, it need be clicked so user can be redirected to target page. That's why my question is how do i click this iframe with JS?
If you use window.open like I specified before, it opens the link you supply. Just change the URL in brackets. Your add site will STILL count this as a click from unique IP adress. However I do not recommend this, because many users will dislike closing new tab. There is no such thing as "click iframe with JS".
The problem is that link in iframe contains picture with a link, so it need to be clicked to deliver user to target page.
...So your problem here is, that you need to first obtain the real link, and then open a new tab with that link. I will look up some solutions, because I'm not sure you can just do that from iframed content...
Thank you for your time! I think i will stick to solution, not to force open that frame and not disturb users :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.