使用jQuery在新窗口中打开.pdf的任何链接?
问题描述:
如何使用jQuery在新窗口中打开带有 .pdf
文件扩展名的所有链接?我需要更改此信息:
How can I have all links with a .pdf
file extension open in a new window using jQuery? I need to change this:
<a href="domain.com/pdf/parkingmap.pdf">parking map</a>
在此:
<a href="domain.com/pdf/parkingmap.pdf" target="_blank">parking map</a>
所有文件都在 / pdf
文件夹中如果这有帮助。
All files are in a /pdf
folder if that helps.
答
要实现这一目标,您可以选择任何 a
元素,其 href
属性以 .pdf
结尾,并添加 target =_ blank
属性。试试这个:
To achieve this you can select any a
element which has a href
property ending with .pdf
, and add a target="_blank"
attribute to it. Try this:
$(function() {
$('a[href$=".pdf"]').prop('target', '_blank');
});