javascript - Intel XDK : document. location.href 导致错误页面

标签 javascript html intel-xdk

你好 Stack Overflow 社区,我一直在搜索和尝试不同的东西,但似乎没有任何效果。在我的英特尔 XDK 项目中,当我尝试使用 location.location.href = "#EndGame"或它的其他形式时,页面确实发生了变化,但它变成了与我要求的页面不同的页面,在我的例子中它发生了变化到“主页”。当我使用按钮而不是 JavaScript 时,它会正常发生。我检查了我的代码,我认为其中没有任何东西会导致问题。那么这是一个错误吗?如果是的话,你能为我建议一种解决方法吗?

我在 JavaScript 和 HTML5 方面不是很熟练,所以这似乎是个糟糕的问题。

这是按钮:

<a class="button widget uib_w_3 d-margins PictWid" data-uib="app_framework/button" data-ver="1" id="Start" style=" margin:0px auto;display:block" onclick="GameLoading()" href="#GamePlay" data-transition="fade">Start</a>

这是js代码:

    function GameOver()
{
     window.clearInterval(Timer);
    window.clearInterval(Timer2);
 w4=0
    for (i = 0; i < level; i++) 
    {
        CenterX[w4] = -100;
        CenterY[w4] = -100;
        w4+=1;
    }

    ShowGold();
    Draw1();

    level=0;
m=0;
k=0;
k2=0;
x3= 0+24.72;
y3 = hei2 - 24.72;
vx=0;
vy=0;
x2 = wid2/2;
y2 = hei2/2;
x = wid2/2;
y = hei2/2;

    setTimeout(function(){document.location.href = "#EndGame"},500);
    EndGamePage();
}

function EndGamePage()
{
     wid2 = screen.width;
    hei2 = screen.height;
    wid = screen.width - 20;
    hei = screen.height - 20;
if (wid < hei)
{   
    //alert("Testing2!")
    document.getElementById("Title2").style.width = wid + "px";
    document.getElementById("Start2").style.width = wid + "px";
    document.getElementById("Title2").style.marginTop = hei2*0.15 + "px";

} else
{
   // alert("Testing3!")
    document.getElementById("Title2").style.width =  hei + "px";
    document.getElementById("Start2").style.width = hei + "px";
    document.getElementById("Title2").style.marginTop = wid2*0.15 + "px";
} 

}

最佳答案

您不能让链接同时处理 href 和点击时触发的函数,因此正确的解决方案是将此行添加到您的函数 GameLoading() 中,或者从中调用一个新函数功能:

window.location+="/#EndGame"

不确定这是否适用于英特尔 XDK,但值得一试。

关于javascript - Intel XDK : document. location.href 导致错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25108987/

相关文章:

javascript - Chrome网络检查器: Is it possible to find the calls for a specific DOM element?

javascript - 如何允许任何人在网页之外运行我的谷歌脚本

html - CSS 悬停无法按预期工作

android - 使用插件 Crosswalk Intel XDK

javascript - OneSignal 获取玩家 ID

css - jquery.mobile-1.4.1 不允许自定义设置页脚导航栏图标

javascript - 搜索多个 html #ID 并传递给函数

javascript - 来自外部 javascript 文件的 Django ajax 请求

jquery - 扩展子 block 时增加父 block 高度(绝对)

java - 如何使用Jsoup通过ID查找元素?