Results 1 to 2 of 2

Thread: Javascript Close Event.

  1. #1

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    Exclamation Javascript Close Event.

    I have a frame called viewer.

    When a herf link if pressed within the frame i would like to check to see if the link they have pressed is a internal link, I.E. is it a link to another part of my site or if another site is going to load within the frame.

    I am trying to use the a onClose event to excute javascript to check this. and if it is a extranel link, stop the unload and open up the link in a new window. I have try using PHP to parse the pages and add target="_blank" but because all these pages have been programmed by different people no one uses a standard <a> so a regular expression can't be created so it works all the <a> tags.

    so far i have,

    just need to know a var that contains the new url that the page is going to change to.

    <script>

    var cmpto = top.document.location;
    cmpto = cmpto.substring(0, cmpto.indexOf("/", 7));
    var newloc = ????;
    newloc = newloc.substring(0, cmpto.indexof("/", 7));
    if (cmpto == newloc) {
    // extranel link.
    window.open(newloc);
    return false;
    }else {
    // do nothing
    return true;
    }
    Digitalmyth

  2. #2

    Thread Starter
    Addicted Member DigitalMyth's Avatar
    Join Date
    Nov 2002
    Location
    England..
    Posts
    169

    Re: Javascript Close Event.

    Seems like i was going the wrong way about it, running this script at the bottom of each pages does what i need.

    <script>

    var test = document.location.href;
    test = test.substring(0, (test.indexOf('/',8) +1));
    for(a = 0; a < document.links.length; a++)
    {
    if(document.links[a].href.substring(0, test.length) != test) {
    document.links[a].target = "_blank";
    }
    }
    </script>
    Digitalmyth

Posting Permissions

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



Click Here to Expand Forum to Full Width