ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

I need to write a conditional to check if a link is external

December 10, 2011 12:59am

Subscribe [3]
  • #1 / Dec 10, 2011 12:59am

    astuteo

    36 posts

    As is the case with every third client or so, my latest wants external links to open in a new window. Unfortunately, things are pretty complicated as it is and I don’t want to add something goofy like an extra checkbox fieldset.

    Is there any easy way to check if a field contains an external link, so I can throw a target=“_blank” in a conditional?

    For what it’s worth, the aforementioned link is currently being added into a Matrix textarea field as a relative path. I’d like to allow both relative and full paths (or find some sort of ultra simple link field for Matrix that I can drop in).

  • #2 / Dec 10, 2011 8:05am

    tidy

    196 posts

    I find it easier to handle this with jQuery instead.
    If you google, you will find lots of code examples with slight variations e.g. http://www.unseenrevolution.com/jquery-external-links-new-window/

    So you just need to include the couple of lines of jQuery on each page of your site and every external link will open in a new window sitewide.

  • #3 / Dec 10, 2011 10:40pm

    astuteo

    36 posts

    Thanks, worked like a charm. Resolved.

  • #4 / Dec 11, 2011 8:39am

    Sean C. Smith

    3818 posts

    Astuteo,

    Glad to see that Janines linke helpe you. Feel free to post again as needed.

    Sean

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases