1

I want to click a div or actually an iframe, and when i click the iframe i want to get the same content of that iframe to another iframe i got. I tried it like this but it will not work for me..

    var leser = document.getElementById("leser");
    var leser2 = document.getElementById("leser2");
    var leser1 = document.getElementById("leser1");

   leser.addEventListener("click", activateLeser);

      function activateLeser() {

      leser1.innerHTML = leser.innerHtmL;

    }

HTML code for the iframes:

  <div id="leser1">
<iframe src="https://opskins.com/?loc=good_deals&sort=n&app=433850_1"></iframe>

<div id="leser">
<iframe src="https://opskins.com/?loc=shop_view_item&item=69274922&uid=76561198258576267"></iframe>

<div id="leser2">
<iframe src="https://opskins.com/?loc=shop_search&sort=lh&app=433850_1&search_item=%22Skin:%20All%20American%20Face%20Bandana%22"></iframe>

Mathias Hermansen
  • 261
  • 1
  • 5
  • 13

2 Answers2

1

Change

leser1.innerHTML = leser.innerHtmL;

to

leser1.src = leser.src;

The changed iframe will reload from scratch instead of copying the contents from the clicked one, but it should work.

Emilio Venegas
  • 546
  • 5
  • 22
1

The problem is that the div is the one calling the event, so clicking the Iframe wont register the event, since the Iframe content is from another page. I would recommend using a button, or allowing some space between the Iframe element and the Div but, if you are bent on doing it that way, try this

//add an Id to your iframe window

//add a click event to the Iframe window

iframe.contentWindow.addEventListener("click", function (event) {activateLeser(this.id); }, false);

it should work. Hope this helps

ps. Also chek out these questions on stack overflow. they are similar to yours Adding click event handler to iframe

capture click on div surrounding an iframe

Community
  • 1
  • 1
Kenny Togunloju
  • 179
  • 1
  • 7