Wednesday, July 25, 2007

Preview Webpage Links

Both "Open link in new Window" and "Open link in new tab" are very useful. They make my web surfing experience a LIFO stack. Where would I be without Shift-click and control-click?

However, there are other cases when you need other functionality. For example, many FAQ sites consist of several links to other pages. Or, you're lost in an extensive site map. When you don't know which link you want, it's slow to have to repeatedly open/close new tabs or windows, and especially slow to go back and forth between pages.

So, I wrote a javascript tidbit to redirect all links to open the page in one specific window. It's like "Open link in Window x" instead of "Open link in new window." (It changes the target attribute of the a tag).

javascript:var thehtml = document.body.innerHTML;thehtml = thehtml.replace(/href="([^"]+)"/gi,'href="$1" target="mynew"');document.write(thehtml);

Try it by going to a webpage with some links (like Wikipedia), copying the code, pasting it into the URL bar, and pressing Enter. It probably will make the page look ugly, but all the links will open in the same window, without you even having to press control or shift.

Below is a more fancy version of the same idea. It lets you "preview" the next webpage in an iframe, in the same window. Not pretty, but it's handy!

javascript:var thehtml = document.body.innerHTML;thehtml = thehtml.replace(/href="([^"]+)"/gi,'href="#" onclick="javascript:document.getElementById(\'ifff\').src=\'$1\';return false"');thehtml = '<div style="float:right; width:600px; height:600px"><iframe style="float:right" src ="'+window.location.href+'" id="ifff" width="100%" height="100%" ></iframe></div>' + thehtml;document.write(thehtml);

No comments: