Open Selected Link Bookmarklet


/ Published in: JavaScript
Save to your folder(s)

When there's a URL on a page that's not a link, just highlight it and click this bookmarklet. The URL will open in a new window.

If there are multiple selections (e.g., if you've selected something in each of two frames on the page), they will each be opened in a new window.

[Open Link](javascript:(function(){function T(f){try{if(f.getSelection)return f.getSelection().toString();if(f.document.selection)return f.document.selection.createRange().text}catch(e){}return ""}function A(f){var a=[];var t=T(f);if(t)a.push(t.replace(/^\s+|\s+$/g,""));for(var i=0;i<f.length;i++){a=a.concat(A(f[i]))}return a}var a=A(window.top);for(var i=0;i<a.length;i++){if(!/^https?:\/\//.test(a[i])) a[i]="http://"+a[i];window.open(a[i])}})() "Drag this into your bookmarks!")


Copy this code and paste it in your HTML
  1. javascript:(function(){function T(f){try{if(f.getSelection)return f.getSelection().toString();if(f.document.selection)return f.document.selection.createRange().text}catch(e){}return ''}function A(f){var a=[];var t=T(f);if(t)a.push(t.replace(/^\s+|\s+$/g,''));for(var i=0;i<f.length;i++){a=a.concat(A(f[i]))}return a}var a=A(window.top);for(var i=0;i<a.length;i++){if(!/^https?:\/\//.test(a[i])) a[i]="http://"+a[i];window.open(a[i])}})();
  2.  
  3. //Here it is expanded so you can read it:
  4. javascript:(function(){
  5. function T(f) //get the selected text in frame f
  6. {
  7. try{
  8. if(f.getSelection) return f.getSelection().toString();
  9. if(f.document.selection) return f.document.selection.createRange().text;
  10. }catch(e){} //if the frame is in another domain
  11. return '';
  12. }
  13. function A(f) //get the selected text in frame f and its children
  14. {
  15. var a = [];
  16. var t = T(f);
  17. if(t)
  18. {
  19. a.push(t.replace(/^\s+|\s+$/g, ''));
  20. }
  21. for(var i=0; i<f.length; i++) //for each child frame
  22. {
  23. a = a.concat(A(f[i]));
  24. }
  25. return a;
  26. }
  27. var a = A(window.top);
  28. for(var i=0; i<a.length; i++)
  29. {
  30. if(!/^https?:\/\//.test(a[i])) a[i] = "http://"+a[i];
  31. window.open(a[i]);
  32. }
  33. })();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.