使用JavaScript重定向到相同/不同的html页面
我在重定向到html页面时遇到问题。我的设想是: 我有两个名为First.html和Second.html的页面。html包含一个返回的链接,即上一页。我已经定义了该链接的使用JavaScript重定向到相同/不同的html页面,javascript,jquery,html,Javascript,Jquery,Html,我在重定向到html页面时遇到问题。我的设想是: 我有两个名为First.html和Second.html的页面。html包含一个返回的链接,即上一页。我已经定义了该链接的href=”“属性。我在它的onClick()事件上调用一个JavaScript函数goBack()。在这篇文章中,我使用window.location.href编写了重定向代码。Bcoz,我想做如下事情: 1。当请求来自First.html时,我必须从Second.html返回First.html <a href="
href=”“
属性。我在它的onClick()
事件上调用一个JavaScript函数goBack()
。在这篇文章中,我使用window.location.href
编写了重定向代码。Bcoz,我想做如下事情:
1。当请求来自First.html时,我必须从Second.html返回First.html
<a href="" onclick=" return goBack()">Back</a>
<script>
var p = window.location.href;
var pre = p.substring(p.lastIndexOf('?') + 3, p.length);
var same = "";
//It changes the contents of Second.html' div tag
someFunction()
</script>
2.当请求来自Second.html时,我必须转到同一页面,即Second.html。html的div内容是使用JavaScript动态更改的,但页面是相同的
我尝试了以下几种选择:
window.location.href
document.location.href
location.href
window.url
window.location.replace(url)
location.assign(url)代码>
谢谢,我自己找到了解决办法 在first.html中
<a href="Second.html?p=First">
令人惊叹的!接下来是什么?那么,您的JavaScript和/或jQuery在哪里?你被困在哪里?你想让我们帮什么忙?
$(document).on('click', '.button1', function() {
// some extra code
same = "Second";
}
var diff;
function goBack() {
if (same == "First") {
diff = pre;
pre = same;
}
if (pre == same) {
location.href = "Second.html?p=" + diff;
same = "";
} else if (pre != 'Second') {
location.assign("" + pre + ".html");
diff = pre;
} else {
location.assign("" + diff + ".html");
}
return false;
}