Open Specific Links In New Windows - jQuery newwindow

Open Specific Links In New Windows - jQuery newwindow
File Size: 3.36 KB
Views Total: 518
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

newwindow is a super tiny jQuery plugin that opens specific anchor links (typically external links) within the document in the new browser windows or tabs.

How to use it:

1. Link to jQuery library and the jQuery newwindow plugin's script:

<script src="//code.jquery.com/jquery.min.js"></script>
<script src="jquery.newwindow.js"></script>

2. Call the function on the desired anchor links (e.g. nofollow and external links) and done.

<a href="https://facebook.com" rel="external">Facebook.com</a>
<a href="https://google.com" rel="nofollow">Google.com</a>
$('a[rel~=nofollow]').newWindow();
$('a[rel~=external]').newWindow();

3. The plugin also provides a callback function which will be triggered when the external links are opened.

$('a[rel~=nofollow]').newWindow({
  open: function (newWindow, e) {
    console.log('Window opened', newWindow, e);
  }
});

This awesome jQuery plugin is developed by alexrabarts. For more Advanced Usages, please check the demo page or visit the official website.