Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window.open name not working

    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:

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

    Any thoughts?

    Thanks

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,901
    Thanks
    56
    Thanked 543 Times in 540 Posts
    Code:
    window.open ("http://www.xxx.com" , "testpage" );

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,901
    Thanks
    56
    Thanked 543 Times in 540 Posts
    mmm... you're not confusing the name of the window with its title are you?

  • #5
    New Coder
    Join Date
    Aug 2010
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello

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

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,901
    Thanks
    56
    Thanked 543 Times in 540 Posts
    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):

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

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    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.)
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    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:
    Code:
    window.open ("http://www.xxx.com?use%20this%20title" , "testpage" );
    And then in the other page:
    Code:
    <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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •