我有以下場景。Javascript set window.name - IE中的問題
網站A被打開使用網站B window.open("Website B", "windowName");
在網站BI有以下代碼:
<script>
window.name='';
window.location.href = 'Website C';
</script>
在網站CI具有在Firefox和鉻(所有版本)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>
添加了證明該問題並要求某人提供解決方法的源代碼。請重新打開。 –
無法重現問題(使用各種瀏覽器,包括MSIE6),雖然在我的情況下,我設置名稱/在單獨的Javascript調用中調用重定向而不是同步 - 是否會在您通過setTimeout調用更改document.location後發生改名字? – symcbean
在頁面C上的IE(所有版本9-11)上,它仍然在頁面B上添加類似內容後顯示window.name ='某個窗口名稱':setTimeout(doRedirect,10000);請注意,我只能訪問頁面B的代碼,所以頁面A和頁面C我無法改變來解決這個問題。 –