How to Open a Link in a New Window using jQuery

September 06, 2012 // In: javascript, jQuery, Web Design

Few days ago, while developing a web application, I’ve to open a link in a new window by pressing an input button. So I write two lines for this.

Many times you have to open a link in a new window by pressing links / buttons or any other element. The process is very simple and easy.

Code:

$(document).ready(function(){
$(‘#link_id’).click(function(){
window.open(‘url‘, ‘name‘, ‘features‘, ‘replace‘);
return false;
});
});

In window.open url is compulsory and remaining other parameters are optional.
Demo:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src=" http://code.jquery.com/jquery-1.8.1.min.js "></script>
<script type="text/javascript">
$(document).ready(function(){
$('#btnLink').click(function(){
window.open('http://sharp-coders.blogspot.com', '_blank' , false);
return false;
});
});
</script>
<head>
<body>
<input type="button" id="btnLink" value="Click Here" /> <br />
</body>
</html>
Add Facebook Comments to Your WordPress themes
How To Force File Download With PHP