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

如何分割URL并以第二个元素实现Webflow页面跳转

Webflow URL参数提取并跳转脚本

原代码问题分析

  • 错误调用window.location.replace():该方法需传入目标URL字符串,而非DOM元素ID
  • window.location是Location对象,不能直接调用split(),需先转为字符串或使用URL API处理
  • 执行顺序错误:跳转语句放在最前面,后续代码无法执行

完整可用脚本(两种方案)

方案1:使用split分割URL

// 获取当前页面完整URL字符串
const currentUrl = window.location.href;
// 用?分割URL得到数组
const urlParts = currentUrl.split('?');

// 检查是否存在?后的目标地址
if (urlParts.length > 1) {
  const targetUrl = urlParts[1];
  // 跳转至目标地址
  window.location.replace(targetUrl);
} else {
  // 无目标地址时的默认处理
  console.log('未检测到跳转目标地址');
}

方案2:使用URL API(更健壮,推荐)

// 用URL API解析当前页面地址
const currentUrl = new URL(window.location.href);
// 提取?后的内容(去掉开头的?)
const targetUrl = currentUrl.search.slice(1);

if (targetUrl) {
  // 跳转至目标地址
  window.location.replace(targetUrl);
} else {
  console.log('未检测到跳转目标地址');
}

Webflow使用步骤

  • 打开Webflow项目,进入目标页面的「页面设置」
  • 找到「自定义代码」板块,选择「页脚代码」
  • 将上述任一脚本粘贴进去,保存后发布项目即可生效

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 18:31:49