Created
January 23, 2018 19:37
-
-
Save debabratakarfa/a5456f7605e2034bd3ef06378d6ce53c to your computer and use it in GitHub Desktop.
Using jQuery to open PDF, Doc, Docx etc file type in new window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("a").filter( function() { | |
return $(this).attr("href").match(/\.(pdf|doc|docx|ppt|pptx|xls|txt|rtf)$/i); | |
} ).attr('target', '_blank'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<meta name="robots" content="noindex, nofollow"> | |
<meta name="googlebot" content="noindex, nofollow"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<title> by dkarfa</title> | |
</head> | |
<body> | |
<a href="http://www.domain.tld/uploads/file.pdf">pdf</a> | |
<a href="http://www.domain.tld/uploads/file.doc">doc</a> | |
<a href="http://www.domain.tld/uploads/file.html">html</a> | |
<a href="http://www.domain.tld/uploads/file.docx">docx</a> | |
<a href="http://www.domain.tld/uploads/file.ppt">ppt</a> | |
<a href="http://www.domain.tld/uploads/file.php">php</a> | |
<a href="http://www.domain.tld/uploads/file.txt">txt</a> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment