Open All External Links in New Tabs

Posted: August 4th, 2010 | Filed under: General

Here is a quick bit of jQuery to make all external links have the target=_blank attribute.

<script type="text/javascript">
$(function(){
$("a[href^='http:']").not("[href*=EXAMPLE.com']").attr({ target: "_blank" });
});
</script>

You could also use this same technique to add a small friendly image next to these links  notifying the user they are about to leave the site.

<script type="text/javascript">
$(function(){
$("a[href^='http:']").not("[href*=EXAMPLE.com']").attr({ target: "_blank" }).append(" <img src=\"outLink.jpg\">");
});
</script>

301 Redirect using URLRewrite

Posted: May 11th, 2010 | Filed under: General

Just in case.. A 301 redirect tells the browser/search engine that the page has permanently been moved to this new address.

First install URLRewrite on a windows server with IIS7 from  http://www.iis.net/download/URLRewrite

After its installed a new button titled URL Rewrite will be added. Select it.

IIS7 URL Redirect

Under Actions click Add Rule(s)

Select Rule with URL Rewrite map

IIS7 Rule With Rewrite MapChange the Rule Action to Redirect and give it any name you wish it makes no difference what it is.

Then under actions click Add Mapping Entry

IIS7 MappingIn the Original Value field give the path to the old page without the http://www.example.com in the above example it redirects /oldpage.html to /newpage.html

Keep adding new Mapping Entries for every page you need to redirect.


Select and Insert in 1 SQL Query

Posted: April 12th, 2010 | Filed under: MsSQL

I really dislike messing with cursors and loops in SQL and so I jump on any chance I get to avoid them. This little SQL-Server trick allow me to perform a select and insert statements in just 1 short query. In the simplest form the query looks like the following.

INSERT INTO Table2 (col1, col2)
SELECT col3, col4
FROM Table1

How about a bit detailed example using the following sample database structure.

Table1
===========
Tbl1_ID (going to assume an auto increment here)
FK_Tbl2_ID
Data_Copy

Table2
===========
Tbl2_ID
Data

Query1: Select Tbl2_ID From Table2 Where Data = 1

For every returned record from query1 it should insert a record into Table1

INSERT INTO Table1 (FK_Tbl2_ID, Data_Copy)
SELECT Tbl2_ID, Data
FROM Table2
WHERE Data = 1

If anyone has seen/done any kind of performance testing on this sort of query would you kindly post them below.