Ajax is another way to include a file in HTML.

Source: Internet
Author: User
<HTML>
<Head>
<Meta name = "generator" content = "Microsoft Visual Studio 6.0">
<Title> </title>
<Script language = JavaScript>
<! --
Function loadhttp (myname, callback, Uri ){
With (this)
{
If (! Document. readystate)
Document. readystate = "completed ";
This. myname = myname;
This. Callback = callback; // 'iframe' is our fallback: a reference to a dynamically created IFRAME buffer.
This. IFRAME = NULL;
Window. _ ifr_buf_count | = 0;
This. iframeid = 'iframebuffer' + window. _ ifr_buf_count ++;
// A loading flag, set to the requested URI when loading.
This. loadinguri = ''; // in MSIE or browsers with no XMLHttpRequest support: fallback to iframes buffers.
// I'm using iframes in MSIE due to XMLHTTP not parsing text/html to a Dom.
// Also used in ie5/MAC, opera 7.x, safari <1.2, some Konqueror versions, etc.
If (document. createelement & document.doc umentelement &&
(Window. Opera | navigator. useragent. indexof ('msie 5.0 ') =-1 ))
{
VaR IFR = Document. createelement ('iframe ');
IFR. setattribute ('id', iframeid );
IFR. setattribute ('name', iframeid );
// Hide with visibility instead of display to fix safari bug.
IFR. style. Visibility = 'den den ';
IFR. style. Position = 'absolute ';
IFR. style. width = IFR. style. Height = IFR. borderwidth = '0px ';
IFRAME = Document. getelementsbytagname ('body') [0]. appendchild (IFR );
}
Else if (document. Body & document. Body. insertadjacenthtml)
{
// Ie5.0 doesn't like createelement 'd frames (won't script them) and ie4 just plain
// Doesn't support it. Luckily, this will fix them both:
Document. Body. insertadjacenthtml ('beforeend', '<IFRAME name = "' + iframeid +
'"Id ="' + iframeid + '"style =" display: none "> </iframe> ');
}
// This helps most ie versions regardless of the Creation method:
If (window. Frames & window. Frames [iframeid]) IFRAME = Window. Frames [iframeid];
IFRAME. Name = iframeid;
}
This. Load (URI );
// Todo: Put in further dom3 lsparser support as a transport layer ...?
Return this;
}; Loadhttp. Prototype. iframesend = function (Uri, formref)
{
With (this)
{
// Routes a request through our hidden IFRAME. Pass a URI, and Optionally
// Reference to a submitting form. requires proprietary 'readystate' property. If (! Document. readystate)
Return false; // opera fix: force the frame to render before setting it as a target.
If (document. getelementbyid)
VaR o = Document. getelementbyid (iframeid). offsetwidth; // either route the form submission to the IFRAME (easy !)...
If (formref)
Formref. setattribute ('target', iframeid );
Else
{
//... Or load the provided URI in the IFRAME, checking for browser bugs:
// 1) Safari only works well using 'document. location '.
// 2) opera needs the 'src' explicitly set!
// 3) Konqueror 3.1 seems to think ifrdoc's location = Window. Location, so watch that too.
VaR ifrdoc = IFRAME. contentdocument | iframe.doc ument; If (! Window. Opera & ifrdoc. Location & ifrdoc. Location. href! = Location. href)
Ifrdoc. Location. Replace (URI );
Else
IFRAME. src = URI;
} // Either way, set the loading flag and start the readystate checking loop.
// Opera likes a longer initial timeout with multiple frames running...
Loadinguri = URI; setTimeout (myname + '. iframecheck ()', (window. Opera? 250: 100 ));
Return true;
}
}; Loadhttp. Prototype. iframecheck = function ()
{
With (this)
{
// Called after a timeout, periodically callitself until the load is complete.
// Get a reference to the loaded document, using either W3 contentdocument or IE's Dom.

Doc = IFRAME. contentdocument | iframe.doc ument;
// Check the IFRAME's. readystate property and callback () If load complete.
// Ie4 only seems to advance to 'interactive 'So let it proceed from there.
VaR IL = IFRAME. Location, DR =! Dr | Doc. readystate;
If (IL & Il. href? Il. href. Match (loadinguri): 1 )&&
(DR = 'complete' | (! Document. getelementbyid & DR = 'interactive ')
| Doc.doc umentelement. innerhtml! = "<Head> {
If (callback)
Callback(doc.doc umentelement | DOC), loadinguri );
Loadinguri = '';
}
Else
{
Alert (1 );
SetTimeout (myname + '. iframecheck ()', 50 );
}
}
}; // *** Public methods ***
Loadhttp. Prototype. load = function (URI)
{
With (this)
{
// Call with a URI to load a plain text document. If (! Uri |! IFRAME)
Return false;
// Route the get through an available transport layer.
If (IFRAME)
Return iframesend (Uri, null );
Else
Return false;
}
};
// -->
</SCRIPT> <Body>
<Span id = "showitem"> </span>
</Body>
<Script language = JavaScript>
<! --
Function onloadshowitem (content, Uri)
{
// Alert (content. innerhtml );
Showitem. innerhtml = content. innerhtml;
}
VaR lhp = new loadhttp ("lhp", onloadshowitem, "hello.htm ");
// -->
</SCRIPT>
</Html>
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.