Google Map It Bookmarklet


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

Highlight an address and click the bookmarklet to open it in Google Maps


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 t=T(f);if(t)return t;for(var i=0;i<f.length;i++){t=A(f[i]);if(t) return t}return ''}var a=encodeURIComponent(A(window.top).replace(/[
  2. ]+/g,", ").replace(/\s+/g," "));if(a)window.open("http://maps.google.com/maps?q="+a)})();
  3.  
  4. //Here it is expanded so you can read it:
  5. javascript:(function(){
  6. function T(f) //get the selected text in frame f
  7. {
  8. try{
  9. if(f.getSelection) return f.getSelection().toString();
  10. if(f.document.selection) return f.document.selection.createRange().text;
  11. }catch(e){} //if the frame is in another domain
  12. return '';
  13. }
  14. function A(f) //get the selected text in frame f and its children
  15. {
  16. var t = T(f);
  17. if(t) return t;
  18. for(var i=0; i<f.length; i++) //for each child frame
  19. {
  20. t = A(f[i]);
  21. if(t) return t;
  22. }
  23. return '';
  24. }
  25. var a = encodeURIComponent(A(window.top).replace(/[
  26. ]+/g, ", ").replace(/\s+/g, " "));
  27. if(a) window.open("http://maps.google.com/maps?q="+a);
  28. })();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.