IE、Firefox兼容form target当前页iframe,javascript动态创建表单对象form设置name属性
2011-09-07 15:01
1046 查看
一、
不兼容的测试代码:
<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>
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");
}
不兼容的测试代码:
<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>
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");
}
相关文章推荐
- 设置iframe内表单target属性以兼容IE、Firefox【转载】
- javascript -- 在IE中如何实现将表单提交给动态创建的iframe
- javascript/js对html元素自定义属性的操作(兼容Firefox和IE) .
- 兼容IE和Firefox的javascript获取iframe文档内容的函数
- 动态设置form表单的action属性的值的方法
- firefox下JS动态创建的form表单元素获取不到值的问题
- javascript createElement()创建input不能设置name属性的解决方法
- jQueue 动态设置form表单的action属性的值和方法
- ★★ 总结:获取 Iframe内的元素对象,兼容ie、firefox
- 动态设置form表单的action属性的值的简单方法
- 创建兼容 IE/FireFox 的 event 及 event 的 srcElement、fromElement、toElement 属性
- javascript获取iframe文档内容(兼容IE和Firefox)
- Javascript同Form表单中name属性名引发的问题
- JavaScript代码实例:拖动对象 Drag Object (兼容:IE、Firefox、Opera ... )
- JavaScript无提示关闭当前页面窗口,兼容IE/Firefox/Chrome (Close the current page window without confirm by JavaScript, support all browsers)
- 20110107 学习记录:动态指定iframe的scr属性 & IE和Firefox的js兼容性整理 & iframe自适应高度
- 动态设置form表单的action属性的值的方法
- js中使用new Date(str)创建时间对象不兼容firefox和ie的解决方式
- javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
- 访问iframe里面的javascript函数、对象,兼容IE、Firefox