2015-08-31 38 views
0

請你幫我限制一個toastr的外觀。給定的情況是,當我登錄系統時,歡迎toastr將僅在主屏幕上出現一次,並且在我退出之前不會再出現在整個會話中。toastr(jquery)只能顯示一次

這裏是我的toastr代碼

setTimeout(function() { 
      toastr.options = { 
       "closeButton": true, 
       "debug": false, 
       "progressBar": true, 
       "positionClass": "toast-top-right", 
       "onclick": null, 
       "showDuration": "500", 
       "hideDuration": "1000", 
       "timeOut": "5000", 
       "extendedTimeOut": "1000", 
       "showEasing": "linear", 
       "hideEasing": "linear", 
       "showMethod": "fadeIn", 
       "hideMethod": "fadeOut" 
      }; 
      toastr.success("Welcome Admin", "Smartcomp Solutions Inc."); 
     },1000); 
+0

使用的一些標誌,以檢查它是否設置或不not.if然後設置,否則離開它。 –

+0

@SuchitKumar 即時通訊新的jQuery,你能告訴我該怎麼做嗎? – Mikael1

+0

嘗試發佈的答案.... –

回答

2

期權

Reference

DEMO

+0

它不工作,我想要的只是顯示toastr一次作爲歡迎通知.. – Mikael1

+0

如果你想只顯示一次使用'setTimeout'而不是'setInterval'和另一個方式是調用toastr沒有'setTimeout'和'setInterval'在'document.ready' –

1

使用"preventDuplicates": true,如果你想顯示只有一次嘗試這個辦法:

toastr.options = { 
 
    "closeButton": false, 
 
    "debug": false, 
 
    "newestOnTop": false, 
 
    "progressBar": false, 
 
    "positionClass": "toast-top-right", 
 
    "preventDuplicates": true, 
 
    "onclick": null, 
 
    "showDuration": "300", 
 
    "hideDuration": "1000", 
 
    "timeOut": "5000", 
 
    "extendedTimeOut": "1000", 
 
    "showEasing": "swing", 
 
    "hideEasing": "linear", 
 
    "showMethod": "fadeIn", 
 
    "hideMethod": "fadeOut" 
 
} 
 
var flag=false; 
 
setInterval(function() { 
 
    if(!flag){ 
 
     flag=true;//store this to compare later 
 
toastr.success("Welcome Admin", "Smartcomp Solutions Inc."); 
 
    } },1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="http://codeseven.github.io/toastr/build/toastr.min.js"></script> 
 
<link href='http://codeseven.github.io/toastr/build/toastr.min.css' rel='stylesheet' type="text/css">

+0

仍然不工作,每次我重新加載頁面它運行toastr, – Mikael1

+0

然後編寫是一個函數的一部分,只有當登錄成功時調用它在這種情況下,你不需要做其他任何事情。 –