0

Not too familiar with javascript. I have done some searching and am having trouble implementing this code into my current project.

Basically want to refresh the iframe when the screen is clicked. I currently have this code:

document.getElementById('').contentWindow.location.reload(true);

I want to integrate it into this code:

    $(".launch").loadthis({ direction: "left", connect: true });

How would I go about this?

km6zla
  • 4,787
  • 2
  • 29
  • 51
Nico
  • 90
  • 1
  • 2
  • 13

2 Answers2

1

There are some issues that are unclear in your question.

1) What do you mean when you say "Screen is clicked" ?

  • Anywhere in the open browser window?
  • Anywhere in the open browser window including the iframe?

2) Is your IFRAME 100% of the width and height of the browser window?

Regardless, below I break down your problem and hopefully give you a solution...

How do we refresh a webpage?

You can refresh a webpage using:

location.reload(true);

How do we refresh an iframe?

You may refresh an IFRAME using the code here: Refresh an iframe

<iframe id="myiframe" src="http://google.com"></iframe>
document.getElementById("myiframe").src = "http://www.google.com?"+(+new Date());

How do we detect the click?

You can use the solution here: https://stackoverflow.com/a/2622026/1688441

document.onclick= function(event) {
    // Compensate for IE<9's non-standard event model
    //
    if (event===undefined) event= window.event;
    var target= 'target' in event? event.target : event.srcElement;

    alert('clicked on '+target.tagName);
};

Remaining issues:

What happens if user clicks within IFRAME?

If the user clicks within the IFRAME, and we control the code of the IFRAME we can have a click listener within the HTML/JAVASCRIPT of the IFRAME and trigger a refresh.

If we have different domains, due to security reasons there is not much that can be done.

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
0
window.addEventListeneder("click", windowClickHandler);

function windowClickHandler(event) {
    document.getElementById('iframe_id').contentWindow.location.reload();
}

Also see this question;

Community
  • 1
  • 1
km6zla
  • 4,787
  • 2
  • 29
  • 51