...

View Full Version : window.open name not working



Staggan
12-27-2011, 04:29 PM
Hello

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?

Thanks

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

Staggan
12-27-2011, 06: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...

Thanks

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

Staggan
12-27-2011, 07:29 PM
Hello

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

xelawho
12-27-2011, 07:35 PM
hello.

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):



<html>
<script>

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?";
window.clearInterval(timer);
}
}

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

Old Pedant
12-28-2011, 12: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.)

felgall
12-28-2011, 11:29 PM
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, 01: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().

Example:


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));
}
</script>


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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum