Results 1 to 7 of 7

Thread: Open Offsite Links in New Window

  1. #1
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Open Offsite Links in New Window

    1) Script Title: Offsite Links in new Window

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...newwindow2.htm

    3) Describe problem: I have got this working great at the moment, so I am very happy. But just with further work on my page, I need an extra feature. I may not have set it up correctly, but what I require is not just the main domain to be excluded, but extra directories off it. That is, I want links to open in a new window from www.mydomain.com and www.mydomain.com/myfirst/, but not from www.mydomain.com/myfirst/mysecond/. At this stage, this is the only one I want excluded, if this makes it any easier.

    Thanks in advance.
    Last edited by baz999; 12-02-2007 at 10:33 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    As you start to get into fine tuning this script along the lines that you are describing, it becomes increasingly more sensible to simply manually add the target attribute to any link that may (in your scheme of things) require it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the reply.

    I have tried putting a target="(_parent, _self, _top)" on the links that I want to always open in the same window, no matter what the check box says. Unfortunately didn't work.

    Do I need to change the script in some way so that it would look for this target attribute first?

    Or am I missing something?

    Thanks again.

  4. #4
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Further testing has shown that even if I place a target="_blank" on a link, if the checkbox is unticked, every link loads in the same window. That is, there doesn't seem to be an override.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    I meant abandon the script and use the target attributes instead.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Sep 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I was able to solve this problem.

    I put
    Code:
    target="_top"
    on the links that I never want to open in a new window, then adjusted the script as such [adding in the red section]:

    Code:
    if (all_links[i].hostname.search(rexcludedomains)==-1 && all_links[i].href.indexOf("http:")!=-1 && all_links[i].target!="_top")
    I don't know how robust this solution is, but it works for my purpose.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    There's more than one way to skin a cat. Aside from the target attribute being deprecated, that's as good a solution as any. My idea would have required use of target too. A script could be written to assign an event to these links that wouldn't involve the target attribute at all. A valid flag like a class name could be used to exempt links.

    I think what you did is fine though. The advantage with my idea of abandoning the script was that non-javascript enabled browsers would be able to follow it. The advantage with my idea for a new script is that it would be technically valid, more 'future proof'.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •