gpt4 book ai didi

javascript - 刷新时重定向到不同的 URL

转载 作者:行者123 更新时间:2023-11-28 06:01:08 25 4
gpt4 key购买 nike

所以我希望当用户刷新页面时我的页面重定向到不同的页面。我希望用户在刷新页面时从 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>

入门.html

index.html 几乎相同

我尝试用谷歌搜索,但我不断收到“元刷新标签”,在这种情况下,这是没有用的。

最佳答案

这将满足您的要求,只需自定义 URL。

<script>
if (sessionStorage.getItem('beenhere') ==='1') {
window.location="http://www.example.com";
}
sessionStorage.setItem('beenhere', '1');
</script>

参见:

参见:Check if page gets reloaded or refreshed in Javascript

关于javascript - 刷新时重定向到不同的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37265673/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com