这似乎是一个普遍的问题,我所看到的解决方案似乎对我不起作用 .
我们有一个动态生成并插入的iframe,其中有一个提交给它的表单 . 在FF和IE8中工作正常,但在7中我们得到iframe名称问题(IE不想使用element.name或element.setAttribute(“name”,))设置iframe名称 .
所以我已将代码转换为:
function insertTrafRepiFrame(){
var contDiv = document.getElementById('trafficReportDiv');
if(contDiv != null){
var iFrame;
try{
iFrame = document.createElement('IFRAME');
}catch(ex){
iFrame = document.createElement('<iframe name="trafficreport">');
}
iFrame.name = "trafficreport";
iFrame.id = "trafficreport";
iFrame.style.border = 0;
iFrame.src = "http://www.frixo.com/widget/widget-report-area.aspx?road=all%38map=small%38latitude=51.1421%38longitude=-0.07545%38radius=50%38roadsearch=no%38roadlink=yes%38reporttype=full";
while(contDiv.hasChildNodes()){
contDiv.removeChild(contDiv.firstChild);
}
contDiv.appendChild(iFrame);
}
}
使用此表单:
<form name="traffic_report" id="traffic_report" target="trafficreport" action="http://www.frixo.com/widget/widget-report.aspx" onsubmit="javascript:return CheckResponse(this);" method="get">
<div id="trafficRepFormInps">
<input type="hidden" name="map" value="small" />
<input type="hidden" name="roadsearch" value="no" />
<input type="hidden" name="roadlink" value="yes" />
<input type="hidden" name="reporttype" value="full" />
<label for="road">Type a road below, i.e. M23:</label>
<input name="road" value="M23" id="road" class="citysearchbox" type="text" />
</div>
</form>
我注意到在开发人员工具中,IE 7模式下的iframe显示了submitName的属性,其中8模式显示了propdescName的属性 . 这种差异会导致这种形式失误吗?或者我错过了其他什么?
谢谢,Psy
(PS . 关于iframe变量名称的iFrame没有呻吟请:p)
2 回答
我认为你用
document.createElement('<iframe name="trafficreport">');
做得对但我不确定它是否被调用,因为
document.createElement('IFRAME')
即使在IE中也可以 .我们使用动态iframe来沙箱跨域JSONP调用,它在IE中运行良好 . 我使用的代码是:
您可以在演示链接上查看working example here单击 . 如果演示有效,则表示代码中存在错误,如果不起作用,则IE配置有问题 .
对我有用的唯一解决方案是通过执行以下操作将元素注入DOM后更改名称:
window.frames [名称] . 名称=名;