最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - toastr (jquery) must only show once - Stack Overflow

programmeradmin0浏览0评论

Can you please help me in limiting the appearance of a toastr. The given situation is that when I log in the system a wele toastr will appear only once at the home screen and would not appear again in the whole session until I log out.

Here's my toastr code

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("Wele Admin", "Smartp Solutions Inc.");
        },1000);

Can you please help me in limiting the appearance of a toastr. The given situation is that when I log in the system a wele toastr will appear only once at the home screen and would not appear again in the whole session until I log out.

Here's my toastr code

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("Wele Admin", "Smartp Solutions Inc.");
        },1000);
Share Improve this question asked Aug 31, 2015 at 11:30 Mikael1Mikael1 452 silver badges11 bronze badges 4
  • use some flag to check if it is set or not.if not then set otherwise leave it. – Suchit kumar Commented Aug 31, 2015 at 11:50
  • @SuchitKumar im new to jquery, can you show me how to do it? – Mikael1 Commented Aug 31, 2015 at 14:16
  • try the answer posted.... – Suchit kumar Commented Aug 31, 2015 at 15:35
  • @Mikael1, Do you find out the answer to this? I have the same problem. HAHA – Levesque Xylia Commented Jul 12, 2021 at 5:40
Add a ment  | 

2 Answers 2

Reset to default 7

use "preventDuplicates": true, in options

Reference

DEMO

If you want to show for only once try this:

 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 pare later
toastr.success("Wele Admin", "Smartp Solutions Inc.");
    } },1000);
<script src="https://ajax.googleapis./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)

  1. 暂无评论