$(window).on('beforeunload',function(){
$.mobile.changePage($(document.location.href="/index.html"),{
transition:"slide",
changeHash:false
});
});
但它没有用。有谁解决方案,我怎么能做到这一点?
感谢。
答案 0 :(得分:0)
获取关键值:
$(document).keypress(function(e) {
if(e.which == 116) {
window.location.href = '/index.html';
}
});
替代方法:
document.onkeydown = fkey;
document.onkeypress = fkey
document.onkeyup = fkey;
var wasPressed = false;
function fkey(e){
e = e || window.event;
if( wasPressed ) return;
if (e.keyCode == 116) {
window.location.href = '/index.html';
wasPressed = true;
}else {
alert("Window closed");
}
}