Mobile Safari和iFrame src属性 [英] Mobile Safari and iFrame src attribute

查看:110
本文介绍了Mobile Safari和iFrame src属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为iFrame设置'src'属性。它在FireFox和Internet Explorer上运行良好。但是,在iPad上进行测试时,更改'src'属性并没有做任何事情。

I am trying to set the 'src' attribute for an iFrame. It works great on FireFox and Internet Explorer. However, when testing on iPad mobile safari changing the 'src' attribute doesn't do anything.

我有一个iFrame,它在HTML中设置了'src'属性。

I have an iFrame that has it's 'src' attribute set in the HTML.

<iframe id="iFrame0" style="margin: 0px; overflow: hidden; padding: 0px; height:80px; width:500px" src='.../loading.gif' frameborder="0"></iframe>

后来我有一些代码试图改变src

Later on I have some code that tries to change the src

var iFrame0 = YAHOO.util.Dom.get('iFrame0');
YAHOO.util.Event.addListener(iFrame0, 'load', function() { alert('test'); });
MyWebService.GetDynamicUrl('someparam', function(url) {
  iFrame0.src = url;
});

事件不仅不会触发,而且URL的内容也不会改变。在我的测试中,我注意到值 iFrame0.src 确实更改为新传入的URL,但页面上的内容不会更改。

Not only does the event not fire, but the content of the URL doesn't change. In my testing I noted that the value iFrame0.src does change to the newly passed in URL, but the content on the page does not change.

然而,我使用YUI来消除我在测试中的潜在问题,我也试图通过以下方式直接访问iFrame:

I am using YUI, however, to eliminate that as a potential problem in my testing I have also tried to directly access the iFrame via:

document.getElementById('iFrame0').attribute("src") = '..../newurl.gif';

仍然不起作用。

推荐答案

最后,我通过动态创建iframe并将其附加到DOM来解决这个问题。我还为id和src属性添加了一个时间戳,以确保没有进行缓存(虽然我不确定是否真的有必要)。

In the end I solved this by dynamically creating the iframe and attaching it to the DOM. I also added a timestamp to the id and src attributes in order ensure no caching is being done (though I'm unsure if that truly is necessary).

var elIFrame = document.createElement("iframe");
var dt = new Date();
elIFrame.src = APP_IMAGEPATH + "/loading.gif?dt=" + dt.getTime();
elIFrame.id = 'newCard2' + dt.getTime();
elIFrame.frameBorder = 0;
elIFrame.scrolling = "no";
elIFrame.style.width = "500px";
elIFrame.style.height = "1.8em";
YAHOO.util.Dom.insertAfter(elIFrame, this.pre + "cardMask");

这篇关于Mobile Safari和iFrame src属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆