Javascript + iframe implement code for refreshing the entire page

Source: Internet
Author: User

Jquery has a load () method. You can use $ ("# div"). load ("/index.html") to load index.html to a div-ID container,
Iframe can also be used, but it is not perfect. For more information, see the discuz websites. If you log on to a layer, it is also a load page, but I found that about: blank is being opened on the left of the status bar. I don't know if I want to set the src of iframe to about: blank, and then edit iframe? But note that when you view the source code, you cannot see the source code of the loaded page when loading the page. You don't know if you have used head analysis just like jquery, add the header information of the loaded page to the header of the home page, and then use the eval () function to execute javascript code?
I used a page as the container carrying the page source code, named do.html, and passed a page to be loaded by uri?do.html!
Example DEMO: http://mi.8866.org: 2/management. aspx/direct point login can be
This page loads two js files
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = "/image/script. ashx/global. js? Ver = 1.0.0 "> </script>
<Script type = "text/javascript" src = "/image/script. ashx/plus. js? Ver = 1.0.0 "> </script>

The source code of do.html is:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> loading... </title>
<Script type = "text/javascript" src = "/image/script. ashx/do. js? Ver = 1.0 "> </script>
</Head>
<Body>
</Body>
</Html>

File: do. js
Copy codeThe Code is as follows:
Document. write ("<script src = \"/image/script. ashx/global. js? Ver = 1.0.0 \ "> </script> ");
Document. write ("<script src = \"/image/script. ashx/plus. js? Ver = 1.0.0 \ "> </script> ");
Window. onload = function (){
J. plus. loadPage ({uri: "/", time: 1 },{
Start: function () {/* the receipt function that starts loading */},
Over: function () {/* loaded receipt function */}});
}

LoadPage is defined as follows:
Copy codeThe Code is as follows:
If (! Typeof (window. j) window. j = new js ();
J. plus = new plus ();
Function plus (){}
Plus. prototype. loadPage = function (r, callback, e, times ){
/*
R request; r. time: Waiting for loading (MS );
Callback: receipt function (callback. start (), callback. over ())
E. element page container ;*/
If (! R. uri) alert ('page uri parameters not be found! ');
Var aj = new ajax ();
Aj. request (r ,{
Start: function () {if (callback. start) callback. start (); if (e) e. innerHTML = 'loading .. '; else {document. body. innerHTML = 'loading ';}},
Error: function (x) {if (e) e. innerHTML = 'loading failed! '; Else document. body. innerHTML = 'loading failed ';},
Success: function (x ){
Var func = function () {if (callback. over) callback. over (); if (e) e. innerHTML = x; else document. write (x );};
If (r. time) {var t = new timer (r. time, func); t. start ();}/* latency display */
Else func ();
}});
}
/* Aj is the ajax request object defined in global. js
* The timer code is defined in plus. js to implement a timer */

The function has been defined. Add the Code where the function needs to be loaded:
File:/management. aspx/
Copy codeThe Code is as follows:
Var bd = j. $ ("mainbody"); // mainbody is a div container
Var uri = "/do.html? Uri =/management. aspx/"+ uri;
Bd. innerHTML = "<iframe src = '" + uri + "'frameborder = '0' width ='" + (j. x ()-200) + "'height = '000000' scrolling = 'no'> </iframe> ";

Because do.html will be slowed down, in do.js, ajaxwill be used to export the returned HTML to do.html.
Online Demo address http://demo.jb51.net/js/menu_iframe/index.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.