0

ホームページにアクセスするたびに数秒間ポップアップしてから消える.swfがあります。そのために私は使用します

 <script type="text/javascript">


        function popUp(url) { a bunch of java add flash stuff}

function testCookie() {
    if (document.cookie.indexOf("popupOnceValue=false") > -1) {
        document.cookie = "popupOnceValue=true;";
        return true;
    } else {
        return false;
    }
}
function popupOnce() {
    if (document.cookie.indexOf("popupOnceValue") > -1) {
        if (testCookie()) {
            popUp("");
        } 
    } else {
        document.cookie = "popupOnceValue=false;";
        if (testCookie()) {
            popUp("wefinance2.swf");
        }
    }
}

function init() {
    popupOnce();
}

window.onload = init;       



                    </script>   

これは素晴らしい作品です。しかし、私は文字通り変数のすべての組み合わせを試して、別のページでまったく同じタイプのポップアップを実行できるようにしました..しかし、Cookieはすでに認識されているため、ポップアップしません.swf) したがって、基本的には、同じポップアップ コード (popUP、testCookie、popupOnce) を 2 回使用できるようにするには、何を変更すればよいでしょうか?? ああ!

自分を狂わせる!!

4

1 に答える 1

0

ページ URL に固有の Cookie 名を保持する必要があります。これを行うには、各ページの Cookie 名をハードコーディングするか、Cookie 名を自動的に生成します。後者を以下に示します。

// Generate a cookie name based on the current URL.
function getCookieName() {
    return 'popup_' + encodeURIComponent(window.location.href);
}

function testCookie() {
    // Find the cookie name for the current page.
    var cookieName = getCookieName();
    if (document.cookie.indexOf(cookieName) > -1) {
        document.cookie = cookieName + "=true;";
        return true;
    } else {
        return false;
    }
}

function popupOnce() {
    // Find the cookie name for the current page.
    var cookieName = getCookieName();
    if (document.cookie.indexOf(cookieName) > -1) {
        if (testCookie()) {
            popUp("");
        } 
    } else {
        document.cookie = cookieName + "=false;";
        if (testCookie()) {
            popUp("wefinance2.swf");
        }
    }
}
于 2013-05-22T16:21:47.880 に答える