You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JS jQuery:如何让自定义提示消息中的超链接在新标签页打开

解决超链接在新标签页打开的问题

嘿,这个问题其实很容易搞定!你当前的代码里生成的<a>标签没指定打开方式,所以默认会在当前窗口跳转。只需要给<a>标签加上target="_blank"属性,就能让链接在新标签页打开了。另外为了安全起见,建议同时加上rel="noopener noreferrer",避免潜在的安全风险(防止新打开的页面通过window.opener访问原页面的上下文)。

修改后的代码如下:

var conceptName = jQuery('#pa_analise_objeto').find(":selected").val(); 
if(conceptName=='sem_revisao') { 
    jQuery("#displayCustomMsg").html("<p>The model will be <br/>printed automatically <a href='https://LINK.HERE.COM' target='_blank' rel='noopener noreferrer' style='color: #2...'>你的链接文本</a></p>");
}

简单解释下这两个属性的作用:

  • target="_blank":明确告诉浏览器在新标签页(或新窗口)中打开链接
  • rel="noopener noreferrer":切断新页面与原页面的关联,避免恶意页面利用window.opener篡改原页面内容,同时也能提升新页面的加载性能

这样修改后,你的链接就能在新标签页正常打开啦!

内容的提问来源于stack exchange,提问作者Jaime Matos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:13:12