Home  >  Article  >  Web Front-end  >  js can realize the method of monitoring the F5 page to refresh the child iframe without refreshing the parent page.

js can realize the method of monitoring the F5 page to refresh the child iframe without refreshing the parent page.

高洛峰
高洛峰Original
2016-12-07 13:37:081903browse

The key point is to prevent the default refresh, so that the external page will not be refreshed, and then specify the refresh iframe. I have given the idea below

document.onkeypress = function(e){
  if(e.keyCode == 116){
    e.preventDefault(); //组织默认刷新
    var iframeSrc = iframe.src;
    iframe.src = iframeSrc;
  }
}

Write the following in the iframe page:

var iframeSrc = parent.iframe.src;
document.onkeypress = function(e){
  e.preventDefault();
  parent.frame.src = iframeSrc;
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn