Evan
Evan

Reputation: 3511

Make specific link open in a new window with jquery

I'm looking for the ability when a link contains, for example /schedule/ in the address, only this link will open in a new window when clicked. I have a series of 5,000+ links that need to open in a new window, which I would need to update manually (no find/replace available), which contains /schedule/ in the address field and I need them all to open in a new window.

This script will enable external links to open in a new window, but can someone please assist if the link contains /schedule/ in the address field? the external algorithm can be removed. Also, can it include a width + height constraint such as 500 x 600?

UPDATED WITH SOLUTION

add this to your library to append the width & height: http://plugins.jquery.com/project/open

<script type="text/javascript">
     $(document).ready(function(){ 
        $("a[href*='/schedule/']").open
          ({
            width:800,
            height:600,
            location:true,
            toolbar:true,
            resizeable:true,
            scrollbars:true
          }); 
      });
</script>

Upvotes: 1

Views: 1951

Answers (2)

Moin Zaman
Moin Zaman

Reputation: 25465

try this:

$("a[href*='/schedule/']").attr('target','_blank');

For width / height constraints you need to open a popup window (lookup window.open...) or use a modal window that can load external content into an iframe.

Upvotes: 2

Jaime
Jaime

Reputation: 6814

same as the one you have but with the Contains selector

$("a[href*='/schedule/']").attr('target','_blank');

Upvotes: 0

Related Questions