Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获取返回按钮链接以返回原始搜索页面?_Javascript_Java_Hyperlink_Browser History_Back - Fatal编程技术网

Javascript 如何获取返回按钮链接以返回原始搜索页面?

Javascript 如何获取返回按钮链接以返回原始搜索页面?,javascript,java,hyperlink,browser-history,back,Javascript,Java,Hyperlink,Browser History,Back,如何获取“返回搜索页面”超链接,以便用户在查看其他页面上的结果后返回到原始搜索选项卡?这是我正在使用的设置 搜索1、搜索2、搜索3都共享一个搜索结果页面。(我不能改变这一点) “搜索结果”页面上有返回搜索页面链接 当用户在“搜索结果”页面上查看某个项目时,他们需要查看该页面 当它们从查看页面返回到搜索结果页面时,“返回到搜索页面”链接将它们返回到查看页面链接(bc函数当前为history.back) 那么,有没有办法让“返回搜索页面”链接将用户返回到第一个原始搜索页面?我想我应该能够存储原始

如何获取“返回搜索页面”超链接,以便用户在查看其他页面上的结果后返回到原始搜索选项卡?这是我正在使用的设置

  • 搜索1、搜索2、搜索3都共享一个搜索结果页面。(我不能改变这一点)
  • “搜索结果”页面上有返回搜索页面链接
  • 当用户在“搜索结果”页面上查看某个项目时,他们需要查看该页面
  • 当它们从查看页面返回到搜索结果页面时,“返回到搜索页面”链接将它们返回到查看页面链接(bc函数当前为history.back)
那么,有没有办法让“返回搜索页面”链接将用户返回到第一个原始搜索页面?我想我应该能够存储原始搜索页面的操作代码,但不确定如何保存它,然后在返回该链接之前,在函数中调用它,而不会被用户查看的任何其他页面覆盖。如果这是一个有效的解决方案,我就是想不出该怎么做

非常感谢您的帮助

返回搜索结果链接当前在.jsp中的显示方式:


当您调用结果搜索页面时,您可以添加一个参数来记住哪个搜索页面调用了它

在搜索页面上:

window.location.href = './result-page.html?caller=Search1'
在结果页面中,您可以这样存储该值:

var url = new URL(document.URL);
var caller = url.searchParams.get("caller"); // Value = Search1

[...]
// On the click of the "Go Back" button
if (caller == "Search1"){
   window.location.href = "./search1.html"
}
else if(caller == "Search2"){
   window.location.href = "./search2.html"
}
else{
   window.location.href = "./search3.html"
}


您还可以使用本地存储保存原始参数或整个链接,然后读取它以让用户返回原始搜索页面

即使在查看结果或重新加载页面时更改了页面,这也会起作用。(当页面更改或重新加载时,javascript中存储为普通变量的任何其他内容都将被清除。)

在转到原始搜索页面中的搜索结果之前,请存储所需信息,如下所示:

localStorage.setItem(“returnURL”,window.location.href);
//或参数
setItem(“param1”、“param1Value”);
然后读取本地存储以在单击返回按钮时将用户返回到其原始搜索状态:

url=localStorage.getItem(“returnURL”);
//或参数
param1=localStorage.getItem(“param1”);
然后我会在函数中调用“caller”吗<代码>javascript:backToSearchView(“调用者”)?
window.location.href = './result-page.html?caller=Search1'
var url = new URL(document.URL);
var caller = url.searchParams.get("caller"); // Value = Search1

[...]
// On the click of the "Go Back" button
if (caller == "Search1"){
   window.location.href = "./search1.html"
}
else if(caller == "Search2"){
   window.location.href = "./search2.html"
}
else{
   window.location.href = "./search3.html"
}