Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Subscription Center - Java Script

(0) ShareShare
ReportReport
Posted on by 140

Hello Community,

does anyone has a java script example for subscription center?

When the contact clicks "do not email" all subscription lists should be deactivated!

Thank you!

Best Regards

Jennifer

  • cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Subscription Center - Java Script

    Hi Jennifer,

    We should put the script on marketing page.

    From my using experience, I always put it after end tag of body element.(And the script should be nested in script tag.)

    3223.JPG

    ---  How do I proceed when we host it externally via iframe?

    I am not so clear about what does "host it externally via iframe" mean.

    Could you share me more details about it?

    As per my understanding, do you mean the form is being hosted on an external website such as Wordpress?

    If so, as far as I know, some WP plugins might create an iframe element on page and custom elements would be put to the iframe.

    To handle such situation, we could:

    > If custom elements were actually put to iframe, then we need to paste form embedding script to web page directly without using plugin. 

    > If iframe is actually another web page, then we should put the script to that corresponding page.

    In a word, elements in iframe couldn't be accessed.(A more accurate statement is that we couldn't inject javascript into iframe.)

    Please kindly point out if I had misunderstood towards your question.

    Regards,

    Clofly

  • Jenni221 Profile Picture
    Jenni221 140 on at
    RE: Subscription Center - Java Script

    Thank you very much!

    And where do i have to put this script? in the marketing form or in the standard marketing page?

    I use the standard subscription center?

    How do i proceed when we host it externally via iframe?

  • Suggested answer
    cloflyMao Profile Picture
    cloflyMao 25,202 on at
    RE: Subscription Center - Java Script

    Hi Jennifer,

    As per my understanding, you could try code below, run it at "afterFormLoad" event of marketing form. 

    1. Get id value of "Do not email" input field and subscription lists in HTML mode of marketing page.

    We can find that "Do not email" element block is named as "data-editorblocktype="Field-checkbox"" and subscription list element block is named as "data-editorblocktype="SubscriptionListBlock"" by system.

    6138.x11.JPG

    2. At change event of "Do not email", check whether the checked property of "Do not email"  equals to true,

    if yes, uncheck other checkbox fields.

    MsCrmMkt.MsCrmFormLoader.on('afterFormLoad', function () {
      document.getElementById("bddafd65-310b-4d51-91b4-d251a5002add").addEventListener('change', function () {
        if (this.checked === true) {
          document.getElementById("66021523-07dd-ea11-a813-000d3aa08990").checked = false;
          document.getElementById("6c80c140-dfe1-ea11-a813-000d3aa08990").checked = false;
        }
      })
    });

    If I checked the "Do not email", then all subscription lists will be unchecked.

    pastedimage1597817059768v1.png

    Regards,

    Clofly

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans