Posted By

andrew8088 on 08/07/10


Tagged


Versions (?)

Open Selected Links in New Tabs


 / Published in: JavaScript
 

Notes\r\n\r\n* Opens all the links in a selection in new tabs (or windows, depending on your browser configuration)\r\n* I want it to open the tabs in the background, but window.focus() only keeps the current tab at the front in Safari. Let me know if you have a solution
  1. var a = document.querySelectorAll('a[href]'), l = a.length;
  2.  
  3. if (window.getSelection&&window.getSelection().containsNode) {
  4. for ( var i = 0; i < l; i++) {
  5. if (window.getSelection().containsNode(a[i],true)) {
  6. window.open(a[i].href);
  7. }
  8. }
  9. window.focus();
  10. }
  11.  
  12. /*
  13. Bookmarklet:
  14. javascript:(function(){var a = document.querySelectorAll('a[href]'),l=a.length;if (window.getSelection&&window.getSelection().containsNode){for(var i = 0; i < l; i++){if(window.getSelection().containsNode(a[i],true)){ var w = window.open(a[i].href); }} window.focus(); }}());
  15. */

Report this snippet  

You need to login to post a comment.