gpt4 book ai didi

javascript - 使用地址栏参数进行客户端重定向

转载 作者:行者123 更新时间:2023-12-03 08:47:46 25 4
gpt4 key购买 nike

我正在尝试创建重定向页面,但需要使用两个参数来创建地址链接。

<!DOCTYPE html>
<!--
Test file
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--<meta http-equiv="refresh" content="0;url=link" />-->
</head>
<body>
<p>Redirecting...</p>
<script language="javascript">
var chapterx = document.getElementById("chapter").value;
var linex = document.getElementById("line").value;
var link = "http://www.mypage.com/help?chapter=" + chapterx + "," + linex;

//window.prompt(link);
window.location = link;
</script>
</body>
</html>

我通过从我的电脑而不是服务器加载页面来测试这一点。

我对 HTML 和 JS 有非常基本的概念,但我不知道我做错了什么。

我从 Redirect from an HTML page 读到了一些内容创建该代码。

另外,有什么方法可以在重定向之前写入“链接”变量来看看会发生什么?

我还安装了 Firebug,但找不到我声明的变量来查看其状态。

最佳答案

您的代码是正确的。但它不会工作,因为 JavaScript 检测到该行上有错误:

var chapterx = document.getElementById("chapter").value;

您的页面上没有任何带有 chapter 的元素ID。您的下一行也是错误的,因为您的页面上没有带有 line 的元素id。

我将其添加到您的代码中:

<div id="chapter"></div>
<div id="line"></div>

<p>Redirecting...</p>之后它成功地将我重定向到: http://www.mypage.com/help?chapter=undefined,undefined

希望这有帮助?:)

关于javascript - 使用地址栏参数进行客户端重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32813987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com