英特尔XDK:document.location.href导致页面错误

时间:2014-08-03 20:52:44

标签: javascript html intel-xdk

Hello 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";
} 

}

3 个答案:

答案 0 :(得分:0)

试试这个

location.hash = "#EndGame";

答案 1 :(得分:0)

您无法使链接处理href和单击时触发的函数,因此正确的解决方法是将此行添加到函数GameLoading(),或者从该函数中调用新函数:

window.location+="/#EndGame"

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

答案 2 :(得分:0)

经过6个月的经验,我发现对我来说最好的方法是使用所谓的“显示”功能/方法。这是:

    function show(shown, hidden, hidden2, hidden3, hidden4) {
        document.getElementById(shown).style.display = 'block';
        document.getElementById(hidden).style.display = 'none';
        document.getElementById(hidden2).style.display = 'none';
        document.getElementById(hidden3).style.display = 'none';
        document.getElementById(hidden4).style.display = 'none';

        return false;
    }    

它的作用是只显示或隐藏指定的div,如果你给它们ID。所以在一个按钮中,您可以:

<a onclick="show('pagetwo', 'pagezero', 'pagethree', 'pageone', 'pagefour');" id='Start' class="ui-btn">Start</a>

相关问题