使用JQuery获取Iframe的当前src [英] Getting the current src of an Iframe using JQuery
本文介绍了使用JQuery获取Iframe的当前src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当用户点击iframe中不是来自同一域的网页上的链接时,我都会收到通知。我知道xss限制,但我需要知道的是在iframe中提供的当前页面。有没有办法在不违反xss规则的情况下执行此操作?
I need to get notified whenever a user clicks a link on a page in an iframe that is not from the same domain. I'm aware of xss restrictions, however all i need to know is the current page being served in the Iframe. Is there a way to do this without violating xss rules?
推荐答案
如果不是因为跨站点脚本限制,这应该有效。很遗憾,我不知道如何在不违反这些限制的情况下获取网址。
If not for cross-site scripting restrictions this should work. Unfortunately I don't know of a way to get the URL without violating these restrictions.
<html>
<head>
<script type="text/javascript">
function GetIFrameUrl()
{
alert('url = ' + document.frames['frame1'].location.href);
}
</script>
</head>
<body>
<a href="#" onclick="GetIFrameUrl();">Find the iFrame URL</a>
<iframe name="frame1" src="http://www.google.com" width="100%" height="400"></iframe>
</body>
</html>
这篇关于使用JQuery获取Iframe的当前src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文