use*_*135 17
您可以使用popstate事件来执行此操作:
window.onpopstate = function() {
alert("pop!");
}
Run Code Online (Sandbox Code Playgroud)
或者在jQuery中:
$(window).on('popstate', function(event) {
alert("pop");
});
Run Code Online (Sandbox Code Playgroud)
然而,这也将在向前导航时触发,而不仅是向后导航.
$(function() {
if (window.history && window.history.pushState) {
window.history.pushState('', null, './');
$(window).on('popstate', function() {
// alert('Back button was pressed.');
document.location.href = '#';
});
}
});
Run Code Online (Sandbox Code Playgroud)
小智 5
使用此代码来检测浏览器后退按钮事件
<script>
if (performance.navigation.type == 2) {
alert("Back button clicked");
}
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40171 次 |
| 最近记录: |