Javascript 刷新时重定向到其他URL
因此,当用户刷新页面时,我希望我的页面重定向到其他页面。我希望用户刷新页面时,从Javascript 刷新时重定向到其他URL,javascript,jquery,html,url,Javascript,Jquery,Html,Url,因此,当用户刷新页面时,我希望我的页面重定向到其他页面。我希望用户刷新页面时,从gettingstarted.html重定向到index.html 代码: index.html: <!DOCTYPE html> <html lang="en"> <head> //meta, seo stuff <link rel="stylesheet" type="text/css" href="styles.css"> </head&
gettingstarted.html
重定向到index.html
代码:
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
//meta, seo stuff
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
//body stuff
//below is just a script that redirects to gettingstarted.html upon first visit
<script type="text/javascript">
function redirect(){
var thecookie = readCookie('doRedirect');
if(!thecookie){window.location = 'http://domain.tld/gettingstarted.html';
}}function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}window.onload = function(){redirect();createCookie('doRedirect','true','999');}
</script>
</body>
//元,搜索引擎优化的东西
//身体材料
//下面是第一次访问时重定向到gettingstarted.html的脚本
函数重定向(){
var thecookie=readCookie('doRedirect');
如果(!thecookie){window.location=http://domain.tld/gettingstarted.html';
}}函数createCookie(name,value,days){if(days){var date=new date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires=“;expires=“+date.togmString();}else var expires=“”;document.cookie=name+”=“+value+expires+”;path=/”;}函数readCookie(name){var nameq=name+“=”;var ca=document.cookie.split(“;”);for(var i=0;i
gettingstarted.html
与index.html
我试着用谷歌搜索,但我一直得到“元刷新标签”,在这种情况下,这是没有用的。嗯……你可以这样做:
if ( document.referrer == null || document.referrer.indexOf(window.location.hostname) < 0 ) {
sessionStorage.setItem("is_reloaded", true);
}
// This one will set the sessionStorage.setItem on first visit
if (sessionStorage.getItem("is_reloaded")) {
location.href = 'http://domain.tld/gettingstarted.html';
}
//Next time then if someone reload the page so it will reload the user to that another link
嗯……你可以这样做:
if ( document.referrer == null || document.referrer.indexOf(window.location.hostname) < 0 ) {
sessionStorage.setItem("is_reloaded", true);
}
// This one will set the sessionStorage.setItem on first visit
if (sessionStorage.getItem("is_reloaded")) {
location.href = 'http://domain.tld/gettingstarted.html';
}
//Next time then if someone reload the page so it will reload the user to that another link
这将满足您的要求,只需自定义URL即可
<script>
if (sessionStorage.getItem('beenhere') ==='1') {
window.location="http://www.example.com";
}
sessionStorage.setItem('beenhere', '1');
</script>
if(sessionStorage.getItem('beenher')='1'){
window.location=”http://www.example.com";
}
setItem('beenher','1');
见:
请参阅:这将满足您的要求,只需自定义URL即可
<script>
if (sessionStorage.getItem('beenhere') ==='1') {
window.location="http://www.example.com";
}
sessionStorage.setItem('beenhere', '1');
</script>
if(sessionStorage.getItem('beenher')='1'){
window.location=”http://www.example.com";
}
setItem('beenher','1');
见:
请参阅:您的意思是当用户重新加载页面时手动执行like操作,这样他/她就应该被重定向到其他链接??是@UmairShahYousafzaiyou可以引用此url代码来检测刷新按钮或关闭按钮,只需在您的代码
窗口中添加此代码。event.clientX>=1300
您的意思是当用户重新加载页面时手动执行like操作吗年龄,因此他/她应该被重定向到另一个链接??是@UmairShahYousafzaiyou可以引用此url代码来检测刷新按钮或关闭按钮,只需在代码窗口中添加此代码即可。event.clientX>=1300
不起作用…只是自动重定向@UmairShahYousafzai@DavidvleggerWenher:答案已更新…请稍后查看再次..!此第二种方法将在刷新页面之前重定向用户,即在用户单击刷新按钮或重新加载..时刚好正确!没关系..如果您选择了其他答案…我想您的问题将得到解决..!不起作用…只是自动重定向@UmairShahYousafzai@DavidvleggerWenher:答案已更新…请再次检查..!T他的第二个方法将在刷新页面之前重定向您的用户,即当用户单击“刷新”按钮或“重新加载”时就可以了。没关系。如果您选择了另一个答案…我想您的问题将得到解决。。!