Okay
  Public Ticket #857042
Javascript
Closed

Comments

  •  1
    Jack started the conversation

    Hi,

    I'm trying to call a javascript function but my knowledge of javascript is a little thin.

    I need your assistance because I'm trying to trigger this function using one of the 'GO' buttons in visual composer. This button is used to turn on notifications from a plugin called One Signal. Their support department provided me with the following pieces of java;


    Using the Activate Notification button to trigger notifications:

    Call the following JavaScript when the button is clicked:

    var OneSignal = OneSignal || [];

    OneSignal.push(function() {

      OneSignal.registerForPushNotifications();

    });


    Redirecting to another page after the user has chosen to allow notifications:

    Add the following JavaScript to the page (anywhere) (replace your-new-page-or-site):

    var OneSignal = OneSignal || [];

    OneSignal.push(function() {

      OneSignal.on('subscriptionChange', function(isSubscribed) {

        if (isSubscribed) {

          location.href = "http://your-new-page-or-site";

        }

      });

    });


    I can't seem to find a per-page javascript box, please can you explain how I can add these two functions to a button.

    The buttons CSS class(es) are;

    vc_general vc_btn3 vc_btn3-size-sm vc_btn3-shape-rounded vc_btn3-style-modern vc_btn3-icon-left vc_btn3-color-grey


    Any help or guidance you can give me to make this javascript function work and where I should place it would be greatly appreciated.

    Thanks,

    Best Regards,

    Jack Vanstone

  • [deleted] replied

    Hi Jack,

    If you want to add this JavaScript only then go to Theme Options > Footer > JavaScript & Tracking Code:


    (view large version)