CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Home > CodeDigest >  
Technologies
 


Open all Hyperlinks in a Page in Separate Window using jQuery
Submitted By Satheesh Babu B
On 8/27/2009 10:00:07 AM
Tags: CodeDigest,jQuery  

Open all Hyperlinks in a Page in Separate Window using jQuery

This is a simple but very powerful script which will prove the jQuery library's ability.

 

It will be good if we can open the hyperlinks into a sepeart browser window when the user clicks it. This will make sure youe current page still opened on the user's machine giving him the opportunity to read more in the current page. A common example is, opening a advertisement link in a new window on your site will make the visitor to browse your site for more time instead of moving away.

 

The following script will make all the hyperlinks in the page bolder and add opens the link in new window if clicked.


<script src="../_scripts/jquery-1[1].3.2.js" type="text/javascript"></script>
<script language="javascript">
$(function() {
$('A').css('font-weight', 'bold').attr('target', '_blank');
});
</script>


 

The above code will search for all the hyperlink tag(<A>) and set its target attribute to _blank. Setting target="_blank" will open the target link in a new window instead of trhe current browser window.

Recent Codes
  • View All Codes..