IE 问题:使用 javascript 将表单提交到 iframe

编程入门 行业动态 更新时间:2024-10-28 02:21:10
本文介绍了IE 问题:使用 javascript 将表单提交到 iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图使用 javascript 创建一个 iframe 元素,如下所示:

I was trying to create an iframe element using javascript, like so:

var iframe = document.createElement('iframe'); iframe.setAttribute('name', 'frame_x');

但是,当我尝试使用新创建的 iframe 作为目标提交表单时,IE 会打开一个新窗口,而不是使用 iframe.

However, when I tried submitting a form using the newly-created iframe as target, IE opens up a new window, instead of using the iframe.

form.setAttribute('target', 'frame_x'); form.submit();

这在 Firefox 中完美运行.此外,iframe 已创建,但未使用.

This works perfectly in Firefox. Also, the iframe gets created, but is not used.

推荐答案

您遇到了 Internet Explorer 中的错误.

You've hit a bug in Internet Explorer.

您不能在IE中使用标准DOM方法.setAttribute('name',值);

You CAN NOT set the name attribute of ANY element in IE using the standard DOM Method .setAttribute('name', value);

在 IE 中(在 IE8 标准模式下运行的版本 8 之前)此方法将无法设置名称属性.

In IE (before version 8 running in IE8 standards mode) this method will not work to set the name attribute.

您需要使用以下其中一项:

You need to use one of the following:

//A (any browser) var iframe = document.createElement('iframe'); iframe.name = 'frame_x'; //B (only in IE) var iframe = document.createElement('<iframe name="frame_x"/>'); //C (use a JS library that fixes the bug (e.g. jQuery)) var iframe = $('<iframe name="frame_x"></iframe>'); //D (using jQuery to set the attribute on an existing element) $('iframe:first').attr('name','frame_x');

更多推荐

IE 问题:使用 javascript 将表单提交到 iframe

本文发布于:2023-10-09 17:55:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476378.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   javascript   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!