Thursday, March 14, 2013

Open all PDF files in a new browser window


This can be achieved via JQuery. 

To open pdf files in new browser window : 

<script type="text/javascript"> 
$(document).ready(function() { 
$("a[href*=.pdf]").click(function(){ 
window.open(this.href); 
return false; 
}); 
}); 
</script>
 
Or you can use target=”_self” attribute to open new document in the same window : 

<script type="text/javascript"> 
$(document).ready(function() { 
$("a[href*=.pdf]").click(function(){ 
$(this).attr({"target":"_self"}); 
return false; 
});
}); 
</script>
 
Update:- 
If onclick attribute is present then try this  
$("a[href$='.pdf']").removeAttr('onclick').attr("target","_blank"); 

Hope this helps. 

No comments:

Post a Comment