javascript - Detect iframe src change using jquery - Stack Overflow

Lets say an <iframe> is initially loaded pointing to a certain src. The user clicks on a hyperlin

Lets say an <iframe> is initially loaded pointing to a certain src. The user clicks on a hyperlink and the contents of the iframe changes.

I would like to detect that new src of the iframe in full.

Unfortunately it appears to only provide the original src when a change is detected. It detects the change, just not what it changed to.

Perhaps it is a browser-specific issue. I am using chrome.

$(function(){
    $('iframe').load(function() {
        var src = $("iframe").attr('src')
        alert(src);
    });
});

/

Lets say an <iframe> is initially loaded pointing to a certain src. The user clicks on a hyperlink and the contents of the iframe changes.

I would like to detect that new src of the iframe in full.

Unfortunately it appears to only provide the original src when a change is detected. It detects the change, just not what it changed to.

Perhaps it is a browser-specific issue. I am using chrome.

$(function(){
    $('iframe').load(function() {
        var src = $("iframe").attr('src')
        alert(src);
    });
});

http://jsfiddle/vud8S/7/

Share Improve this question asked Nov 21, 2013 at 18:07 Amy NevilleAmy Neville 10.7k13 gold badges61 silver badges98 bronze badges 1
  • 1 You cannot due to same origin policy – A. Wolff Commented Nov 21, 2013 at 18:13
Add a ment  | 

1 Answer 1

Reset to default 6

Fortunately it is not possible to get an URL of an iframe from a different domain than it's parent page. You will not be able to read the full url.

If you try to read the documents location (of an iframe whose src is a differnt domain) than you will get a permission error that looks similar to this: "Error: Permission denied to get property Location.href"

This is due to "Same Origin Policy". More details on that: http://de.wikipedia/wiki/Same-Origin-Policy

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745291595a4620893.html

相关推荐

  • javascript - Detect iframe src change using jquery - Stack Overflow

    Lets say an <iframe> is initially loaded pointing to a certain src. The user clicks on a hyperlin

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信