一、
不兼容的测试代码:
<body>
<form action="http://www.baidu.com" method="post" id="form_forwrad_forword" >
<input type="submit" value="submit"/>
</form>
<iframe id="loginIframe" width="300" height="300"></iframe>
</body>
</html>
<script language="javascript">
var _form=document.getElementById("form_forwrad_forword");
_form.setAttribute("target","loginIframe");
</script>
<form action="http://www.baidu.com" method="post" id="form_forwrad_forword" >
<input type="submit" value="submit"/>
</form>
<iframe id="loginIframe" width="300" height="300"></iframe>
</body>
</html>
<script language="javascript">
var _form=document.getElementById("form_forwrad_forword");
_form.setAttribute("target","loginIframe");
</script>
IE:点击“submit”提交之后,form表单并未按照预想提交到“loginIframe”这个iframe中。
FF:点击“submit”提交之后,form表单按照预想提交到“loginIframe”这个iframe中。
解决此兼容问题: 在iframe中增加name属性即name=“loginIframe”
<iframe id="loginIframe" name="loginIframe" width="300" height="300"></iframe>
二、解决javascript动态创建表单对象form设置name属性(IE、FF兼容)
function AFTER_FORMCREATE_FN(){
var _iframe;
try { // for I.E.
_iframe= document.createElement('<iframe name="loginIframe">');
} catch (ex) { //for other browsers, an exception will be thrown
_iframe = document.createElement('iframe');
}
_iframe.setAttribute("id","loginIframe");
_iframe.setAttribute("name","loginIframe");
_iframe.setAttribute("height","300");
_iframe.setAttribute("style","display:none;");
document.body.appendChild(_iframe);
var _form=document.getElementById("form_forwrad_forword");
_form.setAttribute("target","loginIframe");
}
var _iframe;
try { // for I.E.
_iframe= document.createElement('<iframe name="loginIframe">');
} catch (ex) { //for other browsers, an exception will be thrown
_iframe = document.createElement('iframe');
}
_iframe.setAttribute("id","loginIframe");
_iframe.setAttribute("name","loginIframe");
_iframe.setAttribute("height","300");
_iframe.setAttribute("style","display:none;");
document.body.appendChild(_iframe);
var _form=document.getElementById("form_forwrad_forword");
_form.setAttribute("target","loginIframe");
}