JavaScript window.location.assign()不工作
我正在开发一款基于HTML的文本冒险游戏,根据用户点击的链接,一种选择会导致下一种选择。我正在使用JavaScript window.location.assign()不工作,javascript,html,Javascript,Html,我正在开发一款基于HTML的文本冒险游戏,根据用户点击的链接,一种选择会导致下一种选择。我正在使用localStorage存储玩家的HP值,当HP值达到0时,游戏应该结束,网站应该更改为“游戏结束”页面。我有两个功能,都可以导航到不同的页面,具体取决于HP是否高于或低于某个数字 function alterHP(value) { if (typeof (Storage) !== "undefined") { var currentHP = parseInt(localSt
localStorage
存储玩家的HP值,当HP值达到0时,游戏应该结束,网站应该更改为“游戏结束”页面。我有两个功能,都可以导航到不同的页面,具体取决于HP是否高于或低于某个数字
function alterHP(value) {
if (typeof (Storage) !== "undefined") {
var currentHP = parseInt(localStorage.HP);
localStorage.HP = currentHP + value;
hp=parseInt(localStorage.HP);
if (hp<=0) {
alert(hp); //For debugging, is showing a negative number, like it should be
/*If the error is syntactical, it is the next line*/
window.location.replace('youLose.html');
/*I used breakpoints and this line IS getting hit*/
/*It's just not going to the 'youLose' page*/
}
}
}
function getResult() {
var currentHP = parseInt(localStorage.HP);
if (currentHP > 4) {
window.location.assign('endAbove4.html');//These both work fine
} else {
window.location.assign('endBelow4.html');//These both work fine
}
}
函数变量hp(值){
if(类型(存储)!=“未定义”){
var currentHP=parseInt(localStorage.HP);
localStorage.HP=当前HP+值;
hp=parseInt(localStorage.hp);
如果(hp使用window.open('youLose.html','u self')使用window.open('youLose.html','u self')
window.close('game');
window.open('../youLose.html');
替换window.location.assign();然后放置在index.html页面中
<script>window.name("game");</script>
window.name(“游戏”);
这将关闭游戏的选项卡,然后在替换原始选项卡的新选项卡中打开youLose.html。Put
window.close('game');
window.open('../youLose.html');
替换window.location.assign();然后放置在index.html页面中
<script>window.name("game");</script>
window.name(“游戏”);
这将关闭游戏的选项卡,然后在替换原始选项卡的新选项卡中打开youLose.html。将检查并让您知道我确实弄乱了窗口。打开()并使其工作。谢谢。将检查并让您知道我确实弄乱了窗口。打开()并使其工作。谢谢。