Home >Web Front-end >JS Tutorial >Dynamically generated iframe method in javascript compatible with mainstream browsers_javascript skills

Dynamically generated iframe method in javascript compatible with mainstream browsers_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:49:571370browse

The following code runs successfully under IE8 but fails in IE9:

Copy code The code is as follows:

document.createElement('');

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

Idea analysis:
Step one: Compatible with IE9, firefox, Opera, Safari and other browsers;

Copy code 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: Because ie6-8 cannot modify the name attribute of the iframe

Copy code 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();
    $(formid).target = ajaxframeid;
    $(formid).action = '&inajax=1';
    $(formid).submit();
    return false;
}

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