使用jQuery在新窗口中打开.pdf的任何链接? [英] Make any link with .pdf open in new window with jQuery?

查看:561
本文介绍了使用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');
});

这篇关于使用jQuery在新窗口中打开.pdf的任何链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆