我们如何使页面上的每个链接都在新标签页中打开?
因此,每个链接重定向都将转到新标签。网站就可以安全使用了
我们可以做到,
<a href="there_links.com" target="_blank">there_links.com</a>
但是由于用户可以在注释部分添加自己的链接,从而支持降价。
很难在页面上的每个链接上设置target="_blank"
。因为这些链接将通过markdown
弹出。
例如,单击here会在此处自动加载页面。宁愿重定向。
答案 0 :(得分:1)
选择页面中的所有锚点,然后使用import time
for i in range(10):
'''your donwload code'''
try:
file = open("yourfile.jpg")
break
except:
time.sleep(10)
函数更新目标属性
setAttribute
let anchors = document.querySelectorAll('a');
for (let i = 0; i < anchors.length; i++) {
anchors[i].setAttribute('target', '_blank')
}
以上脚本可以设置在Vue组件的挂接钩内
答案 1 :(得分:1)
您可以查询没有目标的<a>
并将其设置为:
document.querySelectorAll('a:not([target])').forEach(el => el.target = "_blank")
关键部分仅在将markdown处理为元素之后才运行