我只想給第一次用戶一個我的網站的「旅遊」。我想用JavaScript做。我的意思是,如果用戶從未見過我的網站,並且這是他/她的第一次訪問,他們將獲得關於如何使用該網站的教程。如果他們再次訪問或重新加載頁面,他們不應該看到工具提示。這可以通過JavaScript Cookies來完成嗎?我找到了一個PHP代碼,但現在我想避免使用PHP。如何只顯示第一次訪問者的特定工具提示?
<?php
// Top of the page, before sending out ANY output to the page.
$user_is_first_timer = !isset($_COOKIE["FirstTimer"]);
// Set the cookie so that the message doesn't show again
setcookie("FirstTimer", 1, strtotime('+1 year'));
?>
<H1>hi!</h1><br>
<!-- Put this anywhere on your page. -->
<?php if($user_is_first_timer): ?>
Hello there! you're a first time user!.
<?php endif; ?>
如果不能用JS完成,可以用.htaccess來完成嗎?我也發現了這一點:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^(www\.)?(https?://)?(?!example\.com) [NC]
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,NC]
如果cookie不存在,做你的提示東西。否則,不要。 – MikeSmithDev
我對Cookies沒有任何經驗,我無法在網上找到與我的主題相關的任何內容。 – DaKoder