Javascript is compatible with the iframe method dynamically generated by mainstream browsers _ javascript tips-js tutorial

Source: Internet
Author: User
This article describes how to dynamically generate iframe in javascript compatible with mainstream browsers. If you need it, you can refer to the following code and run it in IE8. An error occurs in IE9:

The Code is as follows:


Document. createElement ('');


Error message: exception: SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)

Train of Thought Analysis:
Step 1: compatible with IE9, firefox, Opera, Safari, and other browsers;

The Code is as follows:

Var iframe = document. createElement ("iframe ");
Iframe. setAttribute ("id", "yui-history-iframe ");
Iframe. setAttribute ("src", ".../images/defaults/transparent-pixel.gif ");
Iframe. setAttribute ("style", "position: absolute; top: 0; left: 0; width: 1px; height: 1px; visibility: hidden ;");


Step 2: compatible with IE6-8: Since the ie6-8 cannot modify the name attribute of iframe

The Code is as follows:


Var oFrame = isIE? Document. createElement ("');
} Catch (e ){
Ajaxframe = document. createElement ('iframe ');
Ajaxframe. name = ajaxframeid;
Ajaxframe. id = ajaxframeid;
}
Ajaxframe. style. display = 'none ';
Ajaxframe. loading = 1;
$ ('Append _ parent'). appendChild (ajaxframe );
} Else if (ajaxframe. loading ){
Return false;
}

_ AttachEvent (ajaxframe, 'load', handleResult );

Showloading ();
Authorization (formidapps.tar get = ajaxframeid;
$ (Formid). action + = '& inajax = 1 ';
$ (Formid). submit ();
Return false;
}

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.