简体   繁体   English

jQuery后退按钮(转到空白页)

[英]JQuery back button (goes to blank page)

I have implemented a button: 我实现了一个按钮:

<ul data-role="listview" data-inset="true" class="ui-listview ui-listview-inset ui-corner-all ui-shadow">
    <li class="ui-body ui-body-b ui-li-static ui-body-inherit ui-last-child">
        <fieldset class="ui-grid-a">
            <div class="ui-block-b"><button id="submitButton" type="submit" class="ui-btn ui-btn-a ui-corner-all">Submit</button></div>
            <div class="ui-block-b"><button id="cancelButton" data-direction="reverse" type="button" class="ui-btn ui-btn-a ui-corner-all">Cancel</button></div>
        </fieldset>
    </li>
</ul>

with accompaning JavaScript function that should make the button act as a "back" button: 带有相应的JavaScript函数,该函数应使该按钮充当“后退”按钮:

$(document).on( 'click', '#cancelButton', function() { 
      window.history.back();
});

All I'm testing at the moment is a transition between two pages, and the button works fine for the first three transitions. 我目前正在测试的只是两个页面之间的过渡,并且该按钮在前三个过渡中工作正常。 On the third transition, instead of going back one page, it goes to a blankpage (I believe this is created by my IDE, NetBeans). 在第三个过渡中,而不是返回一页,而是转到空白页(我相信这是由我的IDE NetBeans创建的)。 When I use the console to call window.history.back() it transitions nicely and does not have any issues whatsoever. 当我使用控制台调用window.history.back()它可以很好地过渡并且没有任何问题。 My question is if there is some interaction between the button and the window.history.back() call that males it go to a blankpage 我的问题是按钮和window.history.back()之间是否存在交互作用,导致男性进入空白页

To make sure that you're not taken back to the blank page, check if history really exists before firing back action: 为了确保您不会回到空白页,请在执行回退操作之前检查历史记录是否确实存在:

if (history.length > 1) {
    history.go(-1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM