/ Published in: JavaScript
Highlight an address and click the bookmarklet to open it in Google Maps
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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(/[ ]+/g,", ").replace(/\s+/g," "));if(a)window.open("http://maps.google.com/maps?q="+a)})(); //Here it is expanded so you can read it: javascript:(function(){ function T(f) //get the selected text in frame f { try{ if(f.getSelection) return f.getSelection().toString(); if(f.document.selection) return f.document.selection.createRange().text; }catch(e){} //if the frame is in another domain return ''; } function A(f) //get the selected text in frame f and its children { var t = T(f); if(t) return t; for(var i=0; i<f.length; i++) //for each child frame { t = A(f[i]); if(t) return t; } return ''; } var a = encodeURIComponent(A(window.top).replace(/[ ]+/g, ", ").replace(/\s+/g, " ")); if(a) window.open("http://maps.google.com/maps?q="+a); })();