1

初めてのユーザーだけに私の Web サイトの「ツアー」を提供したいと考えています。JavaScriptでやりたい。つまり、ユーザーが私の Web サイトを一度も見たことがなく、それが初めての訪問である場合、Web サイトの使用方法に関するチュートリアルが表示されるということです。ユーザーが再度アクセスしたり、ページをリロードしたりしても、ツールヒントは表示されません。これは JavaScript Cookie で実行できますか? 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]
4

1 に答える 1

5

もちろんlocalStorage、「ユーザーが以前にアクセスしたことのある」情報を保存するために使用することをお勧めしますが、Cookie を設定すると、その Cookie が毎回サーバーに送信されるためです。独身。リクエスト。作る。に。君の。サーバ。

だから、これを試してください:

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;
    }
}
于 2013-01-24T21:06:00.260 に答える