我尝试了各种方法在 .ftl 文件中导入的 .js 文件中的新窗口中打开链接,但没有成功。
下面是 .js 中的代码
createAsyncThunk
答案 0 :(得分:0)
${web_url}TermsAndConditions
解析为带有 prop 的对象?只需使用带有 target="_blank"
的链接
<a href="termsandconditions.html" target="_blank">Terms and conditions</a>
这不是有效的 JS
window.location.href = `${web_url}TermsAndConditions`.prop(
"target",
"_blank"
);
答案 1 :(得分:0)
我认为您正在寻找的是 window.open()
(https://developer.mozilla.org/en-US/docs/Web/API/Window/open)。你可以调用类似
window.open('termsandconditions.html');
在你的javascript中。此方法也是一种在新选项卡中打开窗口的普通 JS 方法。目标可以设置如下:
window.open('URL','TARGET');
其中 TARGET 可以留空(如第一个示例)以使用新窗口打开,设置为 _self 以在同一窗口中打开等
答案 2 :(得分:0)
您可以使用 window.open()
方法,如下所示,
$(".termsAndCondition").on("click", function() {
var web_url = localStorage.getItem("webUrl");
window.open(`${web_url}TermsAndConditions`, "_blank");
});
或如下所示的自删除锚标记,
$(".termsAndCondition").on("click", function() {
var web_url = localStorage.getItem("webUrl");
var a = $("<a>").appendTo(document.body).attr({
href: `${web_url}TermsAndConditions`,
target: "_blank"
});
a.get(0).click();
a.remove();
});
答案 3 :(得分:0)
问题现在通过 target="_blank" 解决了,天哪,整个下午我都在错误的文件中工作。我从中间的另一个开发人员那里接手了它,我们实际上在维护 2 个具有 2 个开发环境的项目,而我误认为 1 个为另一个。感谢 @mplungjan、@Finn_Lancaster、@Wazeed。