0

On many websites, they show a new visitor landing on the page displayed in an alert Notification that pops up on the bottom right or left

The code below is working just fine, except I have not been successful in changing the message text which reads:

Turning standard Bootstrap alerts into awesome notifications

I want to change this line of text by a customized message but I cant find how to replace this hard coded message with a variable example:

var welcome = 'Welcome visitor from Australia';

<script type="text/javascript" language="JavaScript">
 'use strict';
$(window).on('load', function() {
    function notify(message, type) {
        $.notify({
            message: message
        }, {
            type: type,
            allow_dismiss: false,
            label: 'Cancel',
            className: 'btn-xs btn-inverse',
            placement: {
                from: 'bottom',
                align: 'right' 
            },
            delay: 2500,
            animate: {
                enter: 'animated bounceInUp',
                exit: 'animated bounceOutUp'
            },
            offset: {
                x: 30,
                y: 30
            }
        });
    };
    notify('Welcome to Notification page', 'inverse'); 
});

$(document).ready(function() {
    function notify(from, align, icon, type, animIn, animOut) {
        $.notify({
            icon: icon,
            title: ' Bootstrap notify ',
            message: 'Turning standard Bootstrap alerts into awesome notifications',
            url: ''
        }, {
            element: 'body',
            type: type,
            allow_dismiss: true,
            placement: {
                from: from,
                align: align
            },
            offset: {
                x: 30,
                y: 30
            },
            spacing: 10,
            z_index: 999999,
            delay: 2500,
            timer: 1000,
            url_target: '_blank',
            mouse_over: false,
            animate: {
                enter: animIn,
                exit: animOut
            },
            icon_type: 'class',
                template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
                            '<button type="button" aria-hidden="true" class="close" data-notify="dismiss">×</button>' +
                            '<span data-notify="icon"></span> ' +
                            '<span data-notify="title">{1}</span> ' +
                            '<span data-notify="message">{2}</span>' +
                            '<div class="progress" data-notify="progressbar">' +
                                '<div class="progress-bar progress-bar-{0}" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div>' +
                            '</div>' +
                            '<a href="{3}" target="{4}" data-notify="url"></a>' +
                        '</div>'
        });
    };
    </script>

I have tried replacing the hard coded phrase by the variable welcome

6
  • More details are needed. Bootstrap version? NotifyJS version? Why do you have two functions with the same name? Also, where did you get that object structure for the first argument of $.notify? I see that the official website mentions this: $.notify( string|object, [ options ]) as a way of initializing, but using {icon:icon, title: title, message:message} doesn't seem to be working. You can pass the a string as your message (first argument) and an options object (second argument), and it will work. Commented Apr 16, 2024 at 20:18
  • Thank you for your observations. The code displayed here is from Sweet Alert documentation (github) and this works just fine on my website
    – Nomada
    Commented Apr 24, 2024 at 16:06
  • If this is from SweetAlert, please edit your question, and add that tag. Though your code is quite different from the standard syntax for both Sweet Alert and Sweet Alert 2. Can you please edit your question, and add the link to the library you're using? This is just so we wouldn't have to guess as to what you're using. Commented Apr 27, 2024 at 11:45
  • I apologyze for not knowing at the time of posting that this code uxsed a library, it ends up that it uses a plugin called PNotify
    – Nomada
    Commented May 23, 2024 at 15:25
  • At npmjs.com/package/pnotify, but still my goal of replacing the static hard coded line for the variable var welcome has not been met you can see a screen capture mp4 of what Im trying to achieve in this URL where the new visitor is displayed instead of a statice message code-example-videos.tiiny.site/Left-corner-notifications.mp4 and the next video example is my own code code-example-videos.tiiny.site/my_flipping_pnotify_code.mp4. thanx much I will not abandone this project still need to resolve it
    – Nomada
    Commented May 23, 2024 at 16:04

1 Answer 1

0

Just change your line of

message: 'Turning standard Bootstrap alerts into awesome notifications',

to

message: 'Welcome visitor from Australia',

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.