www.webdeveloper.com
Results 1 to 3 of 3

Thread: Catch Window Navigation

  1. #1
    Join Date
    Jul 2008
    Posts
    2

    Catch Window Navigation

    Hi everyone,

    I am new to this forum and new to JavaScript as a whole so I appreciate any help you guys can be!

    My question involves catching any form of navigation within a window. I would like to have any links clicked on in the window to have the following tag added to the href: '#miniconsole'. This will help point the user to a specific portion of the page that they bring up. The reason why this must be done on load and not put with the link is because I have no control over the coding on the pages that pop up in the new window. The script must therefore run continously till the window is closed, so that all links clicked on will do this same thing.

    I have tried to catch this event using an 'onload', but with no success. I would appreciate any help you guys can give!

    Code:
    function LoadFunction()
    {
    var isClosed = newwindow.closed;
    var addon = "#miniconsole"
    newlocation = currentlocation + addon
    newwindow.navigate(newlocation);
    
    }
    
    // will open the international customer form
    function openIntlForm() {
    var w=396; /* popup window width*/
    var h=250; /* popup window height*/
    
    var l=(screen.width-w)/2; /*this centers horizontally*/
    var t=(screen.height-h)/2; /*this centers vertically*/
    
    var features="left="+l+",top="+t+",width="+w+",height="+h+",scrollbars=auto";
    var newwindow = window.open(link,"",features);
    newwindow.focus();
    var newlocation = null;
    do {
    var currentlocation = newwindow.location.href
    if (currentlocation != newlocation)
    {
    newwindow.attachEvent( 'onload', LoadFunction);
    newwindow.onload = LoadFunction()
    }
    
    while (isClosed = 'False')
    }
    }

  2. #2
    Join Date
    May 2008
    Posts
    3
    Hi,

    In an onLoad function you could get all the a tags using document.getElementsByTagName, then loop through all the a tags this funciton returns adding a custom onClick event handler function to each one which will perform the actions in your current function: LoadFunction. So you will need two functions:

    1. an onLoad funciton that will attach the event handlers
    2. the custom onClick event handler.

    hope it helps

  3. #3
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    The script will need to be added to the pages that pop up in thhe new window. If you have no control over those pages then you have no way to add a script to do it.

    JavaScript is not allowed to access anything on web pages from other sites unless the page on that site loads the script.
    Stephen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles