如何在刷新时加载特定的网址? [英] How do I load a specific url on refresh?

查看:87
本文介绍了如何在刷新时加载特定的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设某人决定按下F5或浏览器的重新加载"按钮.可以在同一标签中打开特定的网址吗?

Let's say that someone decides to press F5 or the browser's reload button. Is that possible to open a specific url in the same tab?

推荐答案

就像在评论中发布的那样,如果显示提示,则可以使用以下 ugly 骇客来实现:

Like posted in comment, if you display prompt, this is possible using following ugly hack:

var a,b;
window.onbeforeunload = function (e) {
    if (b) return;
    a = setTimeout(function () {
        b = true;
        window.location.href = "//test.com";
    }, 500);
    return "Now you will be redirected to new page if choosing to stay there...";
}
window.onunload = function () {
    clearTimeout(a);
}

这篇关于如何在刷新时加载特定的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆