admin管理员组文章数量:1429127
I want to list an iframe with a classified ad in it. Sometimes the vendors redirect the page to their homepage when the item is no longer available. I want to be able to identify this so I can de-index the item assuming it has sold. What is the best method to acplish this?
I want to list an iframe with a classified ad in it. Sometimes the vendors redirect the page to their homepage when the item is no longer available. I want to be able to identify this so I can de-index the item assuming it has sold. What is the best method to acplish this?
Share Improve this question edited Aug 14, 2015 at 15:53 Dave Powers 2,4032 gold badges35 silver badges37 bronze badges asked Dec 18, 2012 at 0:26 user782993user782993 851 gold badge2 silver badges4 bronze badges 1- From what I can tell, this isn't possible. You can only do this if the iframe refers to content hosted on your domain. – Blender Commented Dec 18, 2012 at 0:30
3 Answers
Reset to default 2You can use jQuery's load function that fires onload or reload.
http://api.jquery./load/
You will need to store the number of times the iframe has reloaded.
Something like,
var reloaded = 0;
$("#iframe_id").load(function(){
reloaded++;
});
You can not detect the location of the iframe when it is in a different domain unless they have the proper headers set for CORS.
The only way to do it without worrying about the other domain is to have your serverside code run a check on the page and see if it redirects.
On the frame load, detect what the URL is:
var frameLoadCount = 0;
var firstURL;
$('iframe').load(function() {
if (frameLoadCount === 0) {
firstURL = $(this).attr('src');
} else {
if (firstURL !== $(this).attr('src')) {
// The iframe has been redirected.
}
}
});
Basically the above code runs everytime the iframe has loaded, checks if it's the first time, if it is, assign the URL to a variable. If it has loaded more than once, check if the original url matches the current url.
This has benefits from just checking if it's loaded more than once, because you can target specific sources etc.
本文标签: javascriptHow can I detect if an iFrame gets redirected to another urlStack Overflow
版权声明:本文标题:javascript - How can I detect if an iFrame gets redirected to another url? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745471404a2659767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论