开发者

Getting iframe's src value after dynamically changing it in IE

After I update an iframe's src attribute using : document.getElementById('iframe1').src = newsrc and then attempt to re开发者_如何学JAVAad it: alert(document.getElementById('iframe1').src); The src I get is the old source and not the new one that was set. Why is this and how can I get the real current src value?


If the src is pointing to a different domain, you can't get it. It's a security feature. I guess IE's way of implementing that security feature is to return the old value for src.

Correction: After reading Pekka's comments, I went ahead and tested it. You can try it too at http://jsfiddle.net/pMtZC/ (caution: alerts).

On all browsers I tested it in (Chromium, Firefox 4, IE 8), the changed src property was returned just fine. If you set it, it will return the value you set to it. It will not, however, change if the user navigates within the iframe (obviously). What version of IE are you using?


Trick it into thinking its not on the local domain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜