gpt4 book ai didi

Javascript 设置 window.name - IE 中的问题

转载 作者:行者123 更新时间:2023-11-29 17:21:19 24 4
gpt4 key购买 nike

我有以下场景。

网站 A 正在使用 window.open("Website B", "windowName");

打开网站 B

在网站 B 中,我有以下代码:

<script>
window.name='';
window.location.href = 'Website C';
</script>

在网站 C 中,我在 Firefox 和 Chrome(所有版本)中 window.name 等于 '',但在 IE(版本 9、10、11)中它等于 'windowName'。

谁能解释一下为什么?当我到达网站 C 时,我需要一种解决方法以始终使用 window.name = ''。我无法在网站 B 中使用 windows.open 打开网站 C,我需要使用 window.location。

添加源代码:

index.html(站点 A)

<!DOCTYPE html>
<html>
<title>Page A</title>
<head>
<script>
function test2(){
window.open("index2.html","Some window name","width=500,height=500");
}
</script>
</head>
<body>
<input type="button" onClick="test2();">
</body>
</html>

index2.html(站点 B)

<!DOCTYPE html>
<html>
<title>Page B</title>
<head>
<script>
document.write("initial window name: [" + window.name + "]<br/><br/>");
window.name=""; //we set it to empty string
document.write("after we set window.name to empty string: [" + window.name + "]"); //all fine in all browsers, shows nothing
document.location= 'index3.html';
</script>
</head>
<body>
</body>
</html>

index3.html(站点 C)

<!DOCTYPE html>
<html>
<title>Page C</title>
<head>
<script>
document.write("initial window name: [" + window.name + "]"); //OK in Firefox (shows nothing). Not OK in IE, shows "Some window name"
</script>
</head>
<body>
</body>
</html>

最佳答案

根据 MSDN 文档,name 属性是可变的:

http://msdn.microsoft.com/en-us/library/ie/ms534187%28v=vs.85%29.aspx

我尝试更改 name 属性,它在 IE9 中工作正常:

http://jsfiddle.net/Guffa/5cBBy/1/

我还尝试将其更改为一个空字符串,并且有效:

http://jsfiddle.net/5cBBy/2/

因此,您的代码可能还有其他问题。

关于Javascript 设置 window.name - IE 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12645374/

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