I have the following scenario.
Website A is opening Website B using window.open("Website B", "windowName");
In Website B I have the following code:
<script>
window.name='';
window.location.href = 'Website C';
</script>
In Website C I have in Firefox and Chrome (all versions) window.name
equal to '', but in IE(versions 9, 10, 11) it is equal to 'windowName'.
Can someone explain why? I need an workaround to always have window.name = ''
when I get to Website C. I cannot use windows.open in Website B to open Website C, I need to use window.location.
Source coded added:
index.html (Site 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 (Site 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 (Site 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>
I have the following scenario.
Website A is opening Website B using window.open("Website B", "windowName");
In Website B I have the following code:
<script>
window.name='';
window.location.href = 'Website C';
</script>
In Website C I have in Firefox and Chrome (all versions) window.name
equal to '', but in IE(versions 9, 10, 11) it is equal to 'windowName'.
Can someone explain why? I need an workaround to always have window.name = ''
when I get to Website C. I cannot use windows.open in Website B to open Website C, I need to use window.location.
Source coded added:
index.html (Site 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 (Site 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 (Site 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>
Share
Improve this question
edited Dec 18, 2013 at 16:20
Stefan Iancu
asked Sep 28, 2012 at 18:25
Stefan IancuStefan Iancu
1431 gold badge2 silver badges13 bronze badges
5
- Added the source code that proves the problem and asked for someone to provide an workaround. Please reopen. – Stefan Iancu Commented Dec 17, 2013 at 14:28
- Unable to reproduce the problem (using various browsers including MSIE6) although in my case, I was setting the name / calling the redirect in seperate Javascript calls rather than synchronously - does it stil happen if you invoke change document.location via a setTimeout after changing the name? – symcbean Commented Dec 18, 2013 at 14:00
- On IE (all versions 9-11) on Page C it still shows window.name = 'Some window name' after adding something like on Page B: setTimeout(doRedirect, 10000); Please note that I only have access to Page B code, so Page A and Page C I cannot change to solve this. – Stefan Iancu Commented Dec 18, 2013 at 16:16
- I can confirm that using on Page A: window.name = "Some window name"; document.location="index2.html"; instead of window.open() makes the issue go away. Please note that I only have access to Page B code, so Page A and Page C I cannot change to solve this. – Stefan Iancu Commented Dec 18, 2013 at 16:25
- 2 I have experienced the same issue in IE11. I think it's down to the way Internet Explorer manages it's tabs internally. My tests have shown that after changing the name property of the window in the document, when the URL of that tab changes, IE re-asserts the original name it specified to the name property. Furthermore, if you duplicate a tab, IE will re-use tabs that were previously closed! I've found this to be the case as tabs that I had previously named and closed had reappeared when duplicating tabs (Ctrl+K). This also happens with anchors with a target of "_blank". – Raj Parmar Commented Nov 5, 2014 at 13:17
2 Answers
Reset to default 4According to the MSDN documentation, the name
property is changeable:
http://msdn.microsoft./en-us/library/ie/ms534187%28v=vs.85%29.aspx
I tried to change the name
property, and it works fine in IE9:
http://jsfiddle/Guffa/5cBBy/1/
I also tried to change it to an empty string, and that works:
http://jsfiddle/5cBBy/2/
So, there is likely something else that is wrong with your code.
I had the same problem and found out that you need to rename the window AFTER you set the new window.location. That worked for me!