links

links

Using JQuery To Open External Links In A New Window

Friday, February 19, 2010 - 10:17

Opening external links in a new window can be useful, but adding target="_blank" can be a real chore. Not only that, but if you are trying to validate the page to XHTML strict then the target attribute will cause errors to appear as it is not defined in XHTML.

An easy solution to this issue is to add the following JQuery to your site. It will look for any links that start with http and do not contain the current domain and add a new click event to them that causes a new window to be opened. This will exclude most links straight away as they will most likely be relative.

Category: 

Transform Text Links Into Anchors

Wednesday, May 28, 2008 - 14:27

Using the strip_tags() function on any user generated input should be common practice in order to stop users putting in odd bits of HTML and messing up your nicely coded HTML. You might want to allow anchor tags to be used, which is fine, but some users might use this to include onmouseover and other events in order to run JavaScript annoyances on the page.

So after stripping all tags from your text you can then run the following function to turn any links into anchor elements. This will work with any plain text that you want to use it on.

Category: