如何在javascript中导航到另一个html页面
我有一个名为default.html的主html文件,其中有两个javascript文件default.js和backend.js 这两个javascript文件在主html中添加如下如何在javascript中导航到另一个html页面,javascript,Javascript,我有一个名为default.html的主html文件,其中有两个javascript文件default.js和backend.js 这两个javascript文件在主html中添加如下 <script src="assets/js/backend.js"></script> <script src="assets/js/default.js"></script> 在backend.js中,如果我调用show
<script src="assets/js/backend.js"></script>
<script src="assets/js/default.js"></script>
在backend.js中,如果我调用showNextPage()在页面加载时执行,页面更改会起作用
showNextPage()
class auth {
}
class storageManager {
}
但是如果我调用showNextPage()在这样的类中执行
class auth {
//...
showNextPage()
}
仅执行showNextPage()中的console.log消息,而不执行页面更改
我不知道发生了什么,由于某种原因,它似乎是窗口。位置更改只在页面加载的早期起作用
这可能是什么原因造成的?我如何修复它
我试过了
window.location.href
window.location.replace
以及其他类似的方法。最重要的是,这个函数已经被证明是有效的,但并不是在一个让我困惑了好几天的类中。我已经多次检查我的代码,但没有结果请尝试将您的
default.js
文件放入此文件
startUp()
eel.expose(startUp);
function startUp(){
showNextPage()
}
function showNextPage(){
console.log("show next page")
window.pathname = '/next.html' //IMPORTANT PART.. origin is the page, like https://stackoverflow.com.. pathname is everything past that
console.log("i guess the page did not change")
}
我希望它能起作用尝试将您的
default.js
文件放入此文件
startUp()
eel.expose(startUp);
function startUp(){
showNextPage()
}
function showNextPage(){
console.log("show next page")
window.pathname = '/next.html' //IMPORTANT PART.. origin is the page, like https://stackoverflow.com.. pathname is everything past that
console.log("i guess the page did not change")
}
我希望它能工作后端.js做的第一件事就是从
default.js
调用一个函数,这个函数可能还没有加载。您应该向脚本
引用添加延迟
,以便它们在运行之前等待所有内容加载。@ScottMarcus如何添加延迟?最好使用window.location.href。将“延迟”添加到脚本标记作为属性。您可能还应该侦听page ready事件。@John我尝试了该方法和许多其他方法
,backend.js
做的第一件事是调用default.js
中的函数,该函数可能尚未加载。您应该向脚本
引用添加延迟
,以便它们在运行之前等待所有内容加载。@ScottMarcus如何添加延迟?最好使用window.location.href。将“延迟”添加到脚本标记作为属性。您可能还应该侦听page ready事件。@John我尝试了该方法和许多其他方法