Cannot show TrustPilot HTML when inserted with JavaScript (jQuery)

Sylar

If I added the TrustPilot html code directly on the HTML page, it works fine but I needed to insert it with jQuery. I see the HTML code when inserted but it's not displaying.

  $(window).on('load', function () {
    var el = $('#some-element');

    el.html( trustPilotHtml() );

    function trustPilotHtml() {
      var str = "<div " +
        "class='trustpilot-widget' " +
        "data-locale='en-GB' " +
        "data-template-id='123456' "+
        "data-businessunit-id='123456' " +
        "data-style-height='500px' " +
        "data-style-width='100%' " +
        "data-theme='light' " +
        "data-stars='4,5' " +
        "data-schema-type='Organization'>" +
        "<a " +
        "href='https://some-url.com' target='_blank'>Trustpilot</a> " +
      "</div>";
      return $(str);
    }
});

Is the only way of getting the element to display properly is to directly inserted into the HTML without javascript?

RckMrkr

No it's not the only way.

You should have a bootstrap script in your inside the HEAD part of your HTML (or close to it). This script takes care of initializing all the widgets (TrustBoxes in Trustpilot lingo) that you have in your HTML.

Of cause that doesn't work if you are injecting the HTML dynmically, so it's also possible to call window.Trustpilot.loadFromElement(trustbox); yourself, when if you need to.

Here trustbox is a HTMLElement, you could get by using document.getElementById("some-element") or similar.

Reference: https://support.trustpilot.com/hc/articles/115011421468

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

jQuery onclick not firing on dynamically inserted HTML elements?

分類Dev

SVG not working when inserted from Javascript

分類Dev

how to show a message using jquery in html when radio button is enabled

分類Dev

show an error when values within range are inserted into sqlite

分類Dev

jQuery fetch data and show on HTML

分類Dev

jQuery/Javascript show result from to

分類Dev

HTML How to show an <iframe> when a button is pressed

分類Dev

Javascript - Show message when "No connectivity detected”

分類Dev

Write HTML code with JavaScript (jquery)

分類Dev

Cannot trim object properties using Javascript or JQuery

分類Dev

Using function .when jQuery in "Javascript"

分類Dev

Generate HTML with JavaScript and jQuery - JavaScript not executing?

分類Dev

jquery show and hide based on html5 data attributes

分類Dev

jQuery .html with object data only show one div

分類Dev

What are these unknown symbols that show up in my HTML when using Notepad?

分類Dev

How to show a picture after clicking the thumbnail using Javascript not jQuery?

分類Dev

Take a new line when using $().html in jQuery

分類Dev

HTML、javascript、jQuery-初心者

分類Dev

HTML、javascript、jQuery-初心者

分類Dev

How can show pop when user typing using javascript?

分類Dev

jQuery not detecting clicks on dynamically inserted element

分類Dev

Wrong number of child divs are inserted with jquery

分類Dev

HTML inserted into QTextEdit does not conform to style sheet

分類Dev

Get the date when the row was inserted MySQL

分類Dev

Uncaught TypeError: Cannot read property 'value' of null, HTML & Javascript

分類Dev

Need to hide an <hr> when jQuery slideToggle is executed, then show when clicked again

分類Dev

UIPasteboard image cannot be inserted in Notes.app ios8

分類Dev

Incorrect value inserted into SQL server table when inserted value is greater than column length

分類Dev

.html()。show()を使用すると、jQueryの「undefined」が出力されます

Related 関連記事

  1. 1

    jQuery onclick not firing on dynamically inserted HTML elements?

  2. 2

    SVG not working when inserted from Javascript

  3. 3

    how to show a message using jquery in html when radio button is enabled

  4. 4

    show an error when values within range are inserted into sqlite

  5. 5

    jQuery fetch data and show on HTML

  6. 6

    jQuery/Javascript show result from to

  7. 7

    HTML How to show an <iframe> when a button is pressed

  8. 8

    Javascript - Show message when "No connectivity detected”

  9. 9

    Write HTML code with JavaScript (jquery)

  10. 10

    Cannot trim object properties using Javascript or JQuery

  11. 11

    Using function .when jQuery in "Javascript"

  12. 12

    Generate HTML with JavaScript and jQuery - JavaScript not executing?

  13. 13

    jquery show and hide based on html5 data attributes

  14. 14

    jQuery .html with object data only show one div

  15. 15

    What are these unknown symbols that show up in my HTML when using Notepad?

  16. 16

    How to show a picture after clicking the thumbnail using Javascript not jQuery?

  17. 17

    Take a new line when using $().html in jQuery

  18. 18

    HTML、javascript、jQuery-初心者

  19. 19

    HTML、javascript、jQuery-初心者

  20. 20

    How can show pop when user typing using javascript?

  21. 21

    jQuery not detecting clicks on dynamically inserted element

  22. 22

    Wrong number of child divs are inserted with jquery

  23. 23

    HTML inserted into QTextEdit does not conform to style sheet

  24. 24

    Get the date when the row was inserted MySQL

  25. 25

    Uncaught TypeError: Cannot read property 'value' of null, HTML & Javascript

  26. 26

    Need to hide an <hr> when jQuery slideToggle is executed, then show when clicked again

  27. 27

    UIPasteboard image cannot be inserted in Notes.app ios8

  28. 28

    Incorrect value inserted into SQL server table when inserted value is greater than column length

  29. 29

    .html()。show()を使用すると、jQueryの「undefined」が出力されます

ホットタグ

アーカイブ