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

如何修改脚本将拼接后的URL通过window.open在新窗口打开?

解决方法

你只需要把原来的window.location.href替换成window.open()方法,直接把拼接好的URL作为第一个参数传进去就行,修改后的完整代码如下:

<script>
function redirectToDemo(event) {
  event.preventDefault();
  const urlField = document.querySelector('input[name="urlInput"]');
  const websiteUrl = urlField.value;
  if(!websiteUrl.trim()){
    return false;
  }
  // 用window.open打开新窗口,传入拼接后的目标URL
  window.open(`https://demo.sndrmsg.com?url=${encodeURIComponent(websiteUrl)}`, '_blank');
  return false;
}
</script>

补充说明

  • _blank参数指定在新窗口打开页面,这是默认行为,也可以省略,但显式写出更直观。
  • 浏览器会拦截非用户主动触发的弹窗,务必确保这个函数是通过用户点击按钮这类交互事件调用的(比如给按钮绑定onclick="redirectToDemo(event)"),否则可能无法正常打开新窗口。

内容的提问来源于stack exchange,提问作者Macky Kyle

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 09:42:32