如何关闭 html 文件 javascript
How to close html file javascript
我在按下按钮时打开一个新的 html 文件:
window.location = "menu.html";
我想在按下按钮后返回 "menu" activity 中的 index.html 文件。
我尝试使用
window.location = "index.html";
但它会创建一个新屏幕,如果我单击 return 按钮转到我的主页,它会 return 转到以前的活动。还有
window.opener.location = '/redirect.html';
window.close();
无效。那么如何关闭菜单 activity 返回到我的主菜单 activity.
PS: 我应该使用 window.location 还是 window.location.href 打开新的 html 文件
提前致谢!
尝试使用 window.open("menu.html", "menu")
。除了打开文件,您还可以将第二个参数传递给 .open
方法,下次您想要打开 menu.html 文件时,您可以使用 window.open("menu.html", "menu")
它将打开已经打开的文件浏览器中的文件。
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
我用
修复了它
history.go(-1);
navigator.app.backHistory();
建议在这个答案中:
Phonegap - navigator.app.backHistory() not working on HTML back button
此外,window.location.href 末尾的 href 用于链接,因此您应该只使用 window.location
我在按下按钮时打开一个新的 html 文件:
window.location = "menu.html";
我想在按下按钮后返回 "menu" activity 中的 index.html 文件。 我尝试使用
window.location = "index.html";
但它会创建一个新屏幕,如果我单击 return 按钮转到我的主页,它会 return 转到以前的活动。还有
window.opener.location = '/redirect.html';
window.close();
无效。那么如何关闭菜单 activity 返回到我的主菜单 activity.
PS: 我应该使用 window.location 还是 window.location.href 打开新的 html 文件
提前致谢!
尝试使用 window.open("menu.html", "menu")
。除了打开文件,您还可以将第二个参数传递给 .open
方法,下次您想要打开 menu.html 文件时,您可以使用 window.open("menu.html", "menu")
它将打开已经打开的文件浏览器中的文件。
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
我用
修复了它 history.go(-1);
navigator.app.backHistory();
建议在这个答案中: Phonegap - navigator.app.backHistory() not working on HTML back button
此外,window.location.href 末尾的 href 用于链接,因此您应该只使用 window.location