使用 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?
推荐答案
如果不是跨站点脚本限制,这应该可以工作.不幸的是,我不知道如何在不违反这些限制的情况下获取 URL.
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屋!
查看全文