我们的页面由表格组成。我该如何禁用退格并询问:'你想返回“Referrer Page Title”吗?
我可以禁用退格,但我需要页面标题引荐网址
window.onkeydown = keydown;
function keydown()
{
if(event.keyCode==8){
if (!confirm("Do you want to go back page?"))
return false;
}
}
我们的页面由表格组成。我该如何禁用退格并询问:'你想返回“Referrer Page Title”吗?
我可以禁用退格,但我需要页面标题引荐网址
window.onkeydown = keydown;
function keydown()
{
if(event.keyCode==8){
if (!confirm("Do you want to go back page?"))
return false;
}
}
You have the document.referrer
property available to tell you the URL.
The best solution is to send an AJAX request to your server with the referrer, let the server fetch the referrer and get the title, and send back this title to the client.
There, you can ask the confirmation.
Pseudo-code:
var xhr = new XMLHttpRequest();
xhr.onload = function() {
confirm('Do you want to return to ' + xhr.responseText + '?');
};
xhr.open('your_url?referrer=' + document.referrer);
xhr.send();
About the "disabling backspace" part, you can use the onbeforeunload
event. Where you'd catch the event and send the ajax request instead.