0

Updated Question

What I want is when every time you click the ads (links) you will have an alert "clicked!"

But when I run the code, it says:

Uncaught SecurityError: Blocked a frame with origin \"null\" from accessing a cross-origin frame.

Kindly check the codes here http://jsfiddle.net/0pmofzty/23/

focus();
var parent = document.activeElement;
var iframe = document.getElementsByTagName('iframe')[0],
    iframeDoc = iframe.contentWindow.document;
var targetLinks = iframeDoc.getElementsByTagName('a');

var listener = addEventListener('blur', function() {
 if(document.activeElement === targetLinks) {
    alert("clicked!");
    focusParentEl();
 }
});

function focusParentEl() {
 iframe.blur();
 parent.focus();
  if(document.activeElement !== parent) {
   setTimeout(focusParentEl, 500);
  }
}
<div id="container">
  <script>
    ll_r = "phinoy";
    ll_hc = "#545454";
    ll_tc = "#545454";
    ll_cc = "#e89d2b";
    ll_dc = "#7f8091";
    ll_w = "";
    ll_nf = "0";
    ll_nc = "0";
    ll_nh = "0";
    ll_nm = "0";
    ll_np = "0";
    ll_pa = "0";
    ll_nt = "0";
    ll_wt = "1";
    ll_fw = "1";
    ll_n = "6";
    ll_cl = "";
    ll_s = "w";
  </script>
  <script src="//www.leadsleap.com/w/js.js"></script>
</div>

This snippet is safe. I get the script from the advertising company called leadsleap, a different domain.

  • Hello, can you precise in which line this error occurs ? Can you also avoid to use "var" to define more than 1 variable ? Can you explain where is your – schlebe Jul 05 '18 at 07:57
  • Hello @schlebe I think the error occur on this one var listener = addEventListener('blur', function() { if(document.activeElement === targetLinks) { alert("clicked!"); focusParentEl(); } }); – Kim Benedict Santiago Jul 05 '18 at 08:06
  • Blocking cross-origin scripting is there as a security precaution to protect users from potentially harmful code such as that present in your jsfiddle. Perhaps it'd be best to explain what you are trying to achieve. [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – P. Moloney Jul 05 '18 at 08:13
  • Hi @P.Moloney Thank you for sharing this one, I'll update this post and explain the problem I'm having more clearly. – Kim Benedict Santiago Jul 05 '18 at 08:18
  • @kim: I'm "moderator" and I will help you to improve your question. But when you say that an error occurs, you must be precise so that others users can help you. If you are not sure of which line produces error; add some alert() lines or better, some console.log("your message") lines or use a Javascript debugger to trace your code. – schlebe Jul 05 '18 at 09:00
  • @kim: I propose that you remove all code that it not nessary to understand your problem. Personlaly, I don't see the utility of your posted html code ! The best example would be to post a simple HTML file that contains javascript and html. – schlebe Jul 05 '18 at 09:01

0 Answers0