SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Open Link in new window - then open other link in the same window!

    I have three 'help' links. I want them to all open in new windows/tabs.

    But, if the new 'help' window had already been opened I want the other links, if they are clicked on, to use that window.

    So at anytime, only two windows will be open...

    Is this possible? ... Does anyone know how to do it?

    Thank you
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Code Javascript:
    if (!window.['helpWindow']) {
        // create help window
    }
    // use help window
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you pmw57... but I am no JS wiz...

    Could you take me through exactly how I would open a new window with the name of 'helpwindow' and then use that window if it is already open...?

    Thank you
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  4. #4
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually nevermind I think I have it....

    One thing though - How do I change the location in the already opened window?
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Code Javascript:
    // Create new window
    window.helpWindow = window.open('', 'helpWindow');
    // Window now referenced as window.helpWindow or window['helpWindow']
     
    // Redirect the window
    window.helpWindow.location.href = 'http://www.google.com';

    Extra for experts: What purpose does the 'helpWindow' name in the open method serve?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    THANK YOU!! - I have it working now!

    Anyway - I have another problem now - I don't think it is worth starting another thread...

    Why does this not work???

    Code JavaScript:
    window.onload = function1('uilink1');
    function function1(linkid) {
    	var thelink = document.getElementById(linkid);
    	var location = thelink.getAttribute('href');
    	alert(location);
    }

    Code HTML4Strict:
    <a href="http://www.google.com" id="uilink1">Link 1</a>
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because this line:
    window.onload = function1('uilink1');

    assigns the return value of function1('uilink1') to window.onload. But what you really want is to assign that function to onload, so use:

    window.onload = function () {function1('uilink1');};

    If there were no parameters you could do

    window.onload = function1;

  8. #8
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks jimfraser - it works perfectly now, plus I learnt something
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    And if you were going to use the function only once, you could use an anonymous function.

    Code Javascript:
    window.onload = function () {
        var linkid = 'uilink1';
        var thelink = document.getElementById(linkid);
        var location = thelink.getAttribute('href');
        alert(location);
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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