gpt4 book ai didi

javascript - jQuery iframe-使用 iframe 时如何获取父窗口 URL?

转载 作者:行者123 更新时间:2023-12-03 08:44:10 27 4
gpt4 key购买 nike

我举了一个例子。

test.html:

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
</head>
<body>
<h1>main window test</h1>
<iframe src="./iframe.html"></iframe>
</body>
</html>

iframe.html:

 <!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<h1>iframe testing</h1>
<script type="text/javascript">
$(document).ready(function() {
alert("window.location.href"+window.location.href);
});
</script>
</body>
</html>

在警报中-->我收到 iframe url“C:\Users\nn96589\Desktop\testfolder\iframe.html”

但是,我需要主窗口 URL,即“C:\Users\nc96589\Desktop\testfolder\test.html”

谁能帮帮我。提前致谢。

最佳答案

尝试使用document.referrer

<iframe src="data:text/html,<!DOCTYPE html><html><body><script>document.write(document.referrer)</script></body></html>">
</iframe>

关于javascript - jQuery iframe-使用 iframe 时如何获取父窗口 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32959800/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com