有没有办法打开所有< a href>新窗口中的页面链接? [英] Is there a way to open all <a href> links on a page in new windows?

查看:154
本文介绍了有没有办法打开所有< a href>新窗口中的页面链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆< a href =。html> 链接,并希望在新窗口中打开它们。

I have a bunch of <a href=".html"> links and want to make them all open in new windows.

我知道我可以进行搜索并全部替换为将 target =_ blank添加到所有我的< a href =...> 链接。

I know I can do a search and replace all to add target="_blank" to all my <a href="..."> links.

然而,有没有一种快捷方式,比如设置CSS样式,或者添加一些JavaScript代码,以完成同样的事情?

However, is there a quick way, such as setting a CSS style, or adding some JavaScript code, to accomplish the same thing?

推荐答案

如果您的页面仅包含链接,请考虑 < base target =_ blank> 。这将打开新窗口中的每个链接(但也包括窗体的目标,除非用< form target =_ self>

If you have a page consisting of only links, consider <base target="_blank">. This opens every link in a new window (but also includes the targets of forms, unless overridden with <form target="_self">.

正如其他人所示,在不修改HTML源代码的情况下,您可以使用JavaScript来遍历所有< a> 标记并添加目标属性或添加事件侦听器,动态设置目标属性

As others have shown, without modifying the HTML source, you can use Javascript to iterate through all <a> tags and add the target attribute or add an event listener that sets the target attribute dynamically.

这篇关于有没有办法打开所有&lt; a href&gt;新窗口中的页面链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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