2012-01-26 25 views
0

このjquery_modal_confirm_dialogueは多くの実験の後に動作しています。 私たちの訪問者は、利用規約に同意すると、彼らは私が必死にクッキーを設定する必要があり、製品のページproducts.htmlクッキー - jqueryモーダルを設定するダイアログを確認する

にリダイレクトされます。 - 一致しない場合、products.htmlにアクセスしようとすると、 は表示されず、再度モーダルダイアログが表示されます

教えてください。 (jqueryの1.3.2.min.js)

これは、これは私のindex.htmlである私のjqmodal.js

function confirm(msg,callback) { 
    $('#confirm') 
    .jqmShow() 
    .find('p.jqmConfirmMsg') 
     .html(msg) 
    .end() 
    .find(':submit:visible') 
     .click(function(){ 
     if(this.value == 'yes') 
      (typeof callback == 'string') ? 
      window.location.href = callback : 
      callback(); 
     $('#confirm').jqmHide(); 
     }); 
} 


$().ready(function() { 
    $('#confirm').jqm({overlay: 88, modal: true, trigger: false}); 

    // trigger a confirm whenever links of class alert are pressed. 
    $('a.confirm').click(function() { 
    confirm('About to visit: '+this.href+' !',this.href); 
    return false; 
    }); 
});// JavaScript Document 

です:私が正しく理解していれば

<a href="http://products.html/" class="confirm">Products</a> 

    <div class="jqmConfirm" id="confirm"> 

    <div id="ex3b" class="jqmConfirmWindow"> 
     <div class="jqmConfirmTitle clearfix"> 
      <h1>Terms of Use</h1> 
     </div> 

     <div class="jqmConfirmContent"> 
     <p class="jqmConfirmMsg"></p> 
      <p>Important legal information</p></div> 

     <input type="submit" value="Decline" /> 
     <input type="submit" value="Proceed" /> 
     </div> 
    </div> 

答えて

0

それは、ついに、動作します!私は、クッキーが存在するときにコールバックを失い、クッキーの値の周りにこれらのチックを置いていました。これはどのように見えるかです。明白な間違いがある場合はお知らせください。 (ご支援いただきありがとうございます)

function confirm(msg,callback) { 
    $('#confirm') 
    .jqmShow() 
    .find('p.jqmConfirmMsg') 
     .html(msg) 
    .end() 
    .find(':submit:visible') 
     .click(function(){ 
     if(this.value == 'Proceed'){ 
      $.cookie("agreed_to_terms", '1', { expires : 1, path: '/' }); //set cookie, expires in 365 days 
      (typeof callback == 'string') ? 
      window.location.href = callback : 
      callback(); 
     } 
     $('#confirm').jqmHide(); 
     }); 
} 


$().ready(function() { 
    $('#confirm').jqm({overlay: 88, modal: 'true', trigger: false}); 

    // trigger a confirm whenever links of class alert are pressed. 
    $('a.confirm').click(function() { 
    if ($.cookie('agreed_to_terms') == '1'){window.location.href = callback = 
      callback() 
     //they already have cookie set 
    }else{ 
     confirm('About to visit: '+this.href+' !',this.href); 
    } 
    return false; 
    }); 
});// JavaScript Document 
+1

答えを正しいものとしてマークしてください。 –

3

確認を受け入れてクッキーを設定するようにします。それから、次回に法律上の問題を表示しないでください。

まず、このjQueryプラグインを取得:

https://github.com/carhartl/jquery-cookie

それはあなたがのようなものを行うことができます:だからあなたがそうのようにコードを修正します

$.cookie("test", 1); 

を:

function confirm(msg,callback) { 
    $('#confirm') 
    .jqmShow() 
    .find('p.jqmConfirmMsg') 
     .html(msg) 
    .end() 
    .find(':submit:visible') 
     .click(function(){ 
     if(this.value == 'yes'){ 
      $.cookie("didAccept", 1, { expires : 365 }); //set cookie, expires in 365 days 
      (typeof callback == 'string') ? 
      window.location.href = callback : 
      callback(); 
     } 
     $('#confirm').jqmHide(); 
     }); 
} 


$().ready(function() { 
    $('#confirm').jqm({overlay: 88, modal: true, trigger: false}); 

    // trigger a confirm whenever links of class alert are pressed. 
    $('a.confirm').click(function() { 
    if ($.cookie('the_cookie') == 1){ 
     //they already have cookie set 
    }else{ 
     confirm('About to visit: '+this.href+' !',this.href); 
    } 
    return false; 
    }); 
});// JavaScript Document 
+0

こんにちはPaul! 迅速な対応に感謝します。 私はそれを正しくやっていると信じていますが、modal_dialogueはもう表示されません。 (おそらくクッキーがうまくいけば、私はそれを壊してしまったかもしれません):D 私のtou.jsにあなたのコードを書きました。 HTMLに沿って他のコードを含める必要がありますか? jqueryのバージョンが適合しない可能性はありますか? クッキーが機能するかどうかを確認するにはどうすればよいですか? (ご理解いただきありがとうございます、これらは第3週目です) –

+0

良い質問です。 http://jsfiddle.net/のコードの例をセットアップして、ここにリンクを投稿できますか?あなたが使っている図書館についてより良いアイデアを得ることができます。 –

+0

私はそれを表示させることができました。 "yes"の代わりに "the_cookie"、 "didAccept"、および "Proceed"という名前に変更されました。 Cookieが設定されているかどうかを確認する方法を学びました。今 唯一の問題は、(...これは私にナットを駆動しているおかげで再び)私はもうリダイレクトされます:( は、はい、私はそれをロードしますいけないクッキーを設定した後で –

関連する問題