Today I found a really neat use for my Get Elements By Content function which I wrote recently. I wanted to create a bookmarklet that allowed me to visit a page, click on the link and turn any UK postcodes in the page to a link to a Google Map. Well, it’s pretty simple –
var pc=gbc('[a-z]{1,2}\\d{1,2}[a-z]? \\d[a-z]{2}'); for(var i=0;i<pc.length;i++){ pc[i].innerHTML=pc[i].innerHTML.replace(/([a-z]{1,2}\d{1,2}[a-z]? \d[a-z]{2})/ig,'<a href="http://maps.google.co.uk/maps?f=q&hl=en&q=$1,UK&ie=UTF8&z=16&om=1&iwloc=addr">$1</a>'); }
Obviously you need to ‘gbc’ function from my last post, but other than that, you just need to turn it into a bookmarklet and away you go. If you have any problems, let me know.
Leave a Reply