我正在尝试从 window.open 访问已解析 URL 的 URL。我知道这听起来很愚蠢,但我想在用户执行一些操作后获取 URL 的值。
这是我一直在玩的代码片段,
function myFunction() {
var myWindow = window.open("http://google.com", "MsgWindow", "width=200,height=100");
document.getElementById("demo").innerHTML =
"The full URL of this page is:<br>" + myWindow.location.href;
}
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
最佳答案
I'd like to get the value of the URL after user performs a few actions.
你不能。您创建的窗口是一个跨域框架,因此您无法访问它的位置。
这是必要的,因为窗口的位置可能包含私有(private)信息——例如,许多较旧的网络应用程序将在 URL 中包含 session ID。
关于javascript - 尝试从 window.open() 访问传递的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54717227/