Home  >  Article  >  Web Front-end  >  Summary of js methods to refresh iframe_javascript skills

Summary of js methods to refresh iframe_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:02:061039browse

A summary of the methods of refreshing iframe in JavaScript. Now assuming that there is an iframe like the following, the N methods of refreshing the iframe are:

Copy code The code is as follows:


The first method: use the name attribute of iframe to locate

Copy code The code is as follows:


or

Copy code The code is as follows:


The second method: use the id attribute of the iframe to locate

Copy code The code is as follows:


Third method: When the src of the iframe is the address of another website (i.e. cross-domain operation)

Copy code The code is as follows:


There are two iframes in the parent page. One iframe is a list of links, and the links in it point to the other iframe for displaying content. Now when the content content is added and a record is added to the linked list, the list iframe needs to be refreshed.
Use parent.location.reload() in the submission js of the content iframe to refresh all the parent pages. Because the other iframe does not have a default URL and can only be selected through the list, only the content of the list iframe is displayed.
Use window.parent.frames["list iframe name"].location="list url" to refresh the list iframe, and the refresh of the content iframe will not be affected after submission.

Copy code The code is as follows:

document.frames("refreshAlarm").location.reload(true);
document.frames("refreshAlarm").document.location.reload(true);
document.frames("refreshAlarm").document.location="http://www.jb51.net/";
document.frames("refreshAlarm").src="http://www.jb51.net/";

Note the difference: document.all.refreshAlarm or document.frames("refreshAlarm") gets the iframe tag in the http://www.jb51.net/ page, so operate on the src attribute it works.
document.frames("refreshAlarm").document gets the content inside the iframe, which is the content in "http://www.jb51.net/".

Summary of the implementation method of javascript(js) automatically refreshing the page:

Refresh every 10 seconds and add the following code snippet to the head tag of the page:

Copy code The code is as follows:


Refresh the page regularly (refresh the page every 2 seconds):

Copy code The code is as follows:


Direct refresh page event:

Copy code The code is as follows:


Direct refresh page event:

Copy code The code is as follows:


Direct refresh page event:

Copy code The code is as follows:

function abc(){
window.location.href="/blog/window.location.href";
setTimeout("abc()",10000);
}

Refresh the frame page:

Copy code The code is as follows:


The above is the entire content of this article, I hope you all like it.

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