Is it possible to tell if the src of an iFrame has

2019-07-25 04:56发布

Is it possible to tell if the source of an iFrame has redirected the client to another page? And if so, tell what page the client got redirected to?

3条回答
别忘想泡老子
2楼-- · 2019-07-25 05:10

onload event

like

<iframe src="http://www.mydomain/" onLoad="alert('fire');"></iframe>

The alert will pop-up whenever the location within the iframe has changed. check it out here also

Here is a question explaining how to get current location of an iframe

查看更多
等我变得足够好
3楼-- · 2019-07-25 05:13

The src attribute won't change if the iframe navigates to a new page, but the location of the iframe's contentWindow will.

If you start the iframe in a page on your own domain you can use the iframes onload event to read iframe.contentWindow.location.href.

Use a try-block, and if it fails because of a cross domain call, you can return that the iframe is now in some remote site.

If it returns a value you can return the url on your site the iframe has navigated to.

查看更多
够拽才男人
4楼-- · 2019-07-25 05:19

Allright, so I've been fiddeling with this script for a while now and I think I've reached a conclusion which I think is worth sharing. Cross-domain is pretty strict, and as far as I know there is no way of telling what url the xmlhttprequest object got passed on to. I did however notice a solution on another site where they suggest using a hidden iFrame (I'm referring to the link in @ayush's answer).

查看更多
登录 后发表回答