如何使用Query params从页面打开另一个html文件



我有两个html文件

  1. index.html
  2. search.html

点击按钮,我想打开search.html并在URL中传递一些查询参数。

我做了这个

const params = new URLSearchParams({
sol: something,
art: art,
querytext: getStartedText
}).toString();
window.location.href = "search.html/query?" + params

在新标签中打开这个

file:///Users/someone/Desktop/someProject/search.html/query?sol=Select+SME+Area&art=Select+Artifact+Types&querytext=

但是404错误表示找不到您的文件。

如果我只做这个

window.location.href = "search.html"

它打开search.html页面。你知道我该怎么修吗?

末尾的斜杠使文件系统认为它是一个文件夹

window.location.href = "search.html/query?" + params

它应该是这样的:

window.location.href = "search.html?" + params

第页。S您应该考虑使用本地web服务器,因为使用file协议不是最佳做法,并且在部署网站时可能会导致意外行为。

最新更新