View Full Version : window.open name not working

12-27-2011, 05:29 PM

I have an onclick function used in my table which opens a new window on clicking the table element.. it works fine except that I seem unable to name the window being opened...

Here is my function for opening the window:

function LinkTo(page){
window.open ("http://www.xxx.com , "testpage" );

Any thoughts?


12-27-2011, 05:38 PM
window.open ("http://www.xxx.com" , "testpage" );

12-27-2011, 07:56 PM
Thanks, but the missing " was an oversite when posting here... although I did have to check in case I was going mad...

But no, it still does not work....

I get Untitled Document as the page name...


12-27-2011, 08:14 PM
mmm... you're not confusing the name of the window with its title are you?

12-27-2011, 08:29 PM

The browser tab shows Untitled Document... as does the header of the browser when that window is shown....

12-27-2011, 08:35 PM

yes, that's the title. You can try this, but be aware that you need permission to change titles - I don't think you can change the title of a page that does not "belong" to you (but I may be wrong):


var timer, win;

function openWin() {
win = window.open('about:blank');
timer = window.setInterval(reTitle, 10);

function reTitle(){
if (win.document.readyState == 'complete')
{ win.document.title="how's this for a title?";

<input type=button value="open window" onclick="openWin()"></input>

Old Pedant
12-28-2011, 01:10 AM
xelawho is trying to tell you that the window *NAME* has no relationship whatsoever to the title that is displayed by the browser. You can only change the title of the window by using <title> in HTML or document.title in JS code. (And, as he correctly points out, you won't be able to change the title if the newly opened window is not coming from the same domain as the opener.)

12-29-2011, 12:29 AM
You can use postMessage() to pass information from JavaScript running on one domain to JavaScript running on a different domain in order to be able to have the one page tell the other to change its title - you will need to have access to be able to insert the necessary JavaScript into both pages in order to use it though. Also antique browsers don't support this command.

One potential security issue with regard to using the window.name field is that another web page may already have set its window to use the name you are assigning and then the new page will end up overwriting the current page in that window or tab instead of opening the new window that you expect.

Old Pedant
12-29-2011, 02:23 AM
If you have control of both pages, then you could instead pass the requested title in the query string, for browsers that don't support postMessage().


window.open ("http://www.xxx.com?use%20this%20title" , "testpage" );

And then in the other page:

<script type="text/javascript">
if ( location.search.length > 1 )
document.title = unescape(location.search.substring(1));

But if you don't have control of the other page and it is in another domain, there's really nothing you can do.