2013-01-24 2 views
1

첫 번째 사용자에게 내 웹 사이트의 "둘러보기"만 제공하고 싶습니다. 나는 JavaScript로하고 싶다. 내 말은 사용자가 내 웹 사이트를 본 적이없고 그 사람이 처음 방문한 경우 웹 사이트 사용 방법에 대한 자습서를 받게된다는 것입니다. 방문자가 다시 방문하거나 페이지를 새로 고침하면 툴팁이 표시되지 않아야합니다. 자바 스크립트 쿠키로이 작업을 수행 할 수 있습니까? PHP 코드를 발견했지만 PHP를 사용하지 않으려합니다. 이 JS 함께 할 수없는 경우방문자에게 처음으로 특정 툴팁을 표시하는 방법은 무엇입니까?

<?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; ?> 

, 그것은 htaccess로 수행 할 수 있습니다? 나는이 정보를 "전에 방문한 사용자가"저장 localStorage를 사용하여 선호하지만 당신은 다음 쿠키를 설정하면 그 쿠키가 모든으로 서버로 전송되기 때문에,

RewriteEngine on 
RewriteCond %{HTTP_REFERER} ^(www\.)?(https?://)?(?!example\.com) [NC] 
Rewriterule ^(.*)$ http://example.com/welcome.html [r=307,NC] 
+0

경우, 툴팁 물건을한다. 그렇지 않으면하지 마십시오. – MikeSmithDev

+0

쿠키 사용 경험이 없으므로 온라인에서 내 주제와 관련된 것을 찾을 수 없습니다. – DaKoder

답변

4

물론 : 나는이를 발견했다. 단일. 의뢰. 만든. 에. 너의. 섬기는 사람.

그래서,이 시도 : 쿠키가없는이

if(!window.localStorage) { 
    // no localStorage (old browser) - either fall back to cookie method, 
    // or just do nothing and skip the whole tour thing - if the user 
    // can't be bothered to upgrade, why should you bother to accomodate them? 
} 
else { 
    if(!window.localStorage.isReturningVisitor) { 
     // do all the tour stuff here 
     window.localStorage.isReturningVisitor = true; 
    } 
} 
+0

예! 로컬 저장소! 쿠키보다 훨씬 더 좋아합니다. 나는 그것이 가능하다는 것을 몰랐다. 나는 이것을 지금 시험 할 것이다. – DaKoder

+0

"do nothing"제안을 따르려면 'if (window.localStorage &&! window.localStorage.isReturningVisitor) {/ * do tour * /}'를 사용하십시오. –

+1

JSFiddle을 만들 수 있습니까? – DaKoder

관련 문제