【问题标题】:Trustpilot: window.Trustpilot.loadFromElement is undefined (Safari)Trustpilot:window.Trustpilot.loadFromElement 未定义(Safari)
【发布时间】:2022-01-29 01:18:51
【问题描述】:

我想在我的 Angular 应用程序中放置 3 个 trustPilot。

import { Component, Input, OnInit } from '@angular/core';
declare global {
    interface Window { Trustpilot: any; }
}
 
window.Trustpilot = window.Trustpilot || {};

@Component({
    selector: 'app-trustbox-normal',
    templateUrl: './trustbox-normal.component.html',
    styleUrls: ['./trustbox-normal.component.scss']
})
export class TrustboxNormalComponent implements OnInit {

    constructor() { }

    ngOnInit(): void { }

    ngAfterViewInit(){
        const trustboxRef = document.getElementById('trustbox');
        window.Trustpilot.loadFromElement(trustboxRef);
    }

}

在 Brave 上,Firefox 工作正常,但在 Safari 上出现错误:
window.Trustpilot.loadFromElement 不是函数。 (在'window.Trustpilot.loadFromElement(trustboxRef)'中,'window.Trustpilot.loadFromElement'未定义)

【问题讨论】:

    标签: angular typescript undefined trustpilot


    【解决方案1】:

    可能与这个Trustpilot TrustBoxes in Next.js有关

    您是否尝试过为 loadFromElement 的调用添加延迟,以便为 Truspilot js 脚本提供足够的时间来加载?

    【讨论】:

    • 我建议不要在答案中使用修辞问题。他们冒着被误解为根本不是答案的风险。您正在尝试回答此页面顶部的问题,不是吗?否则请删除此帖。
    【解决方案2】:

    我从代码中删除了window.Trustpilot = window.Trustpilot || {};,现在它在 Safari 上也可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 2020-06-20
      • 1970-01-01
      • 2018-01-06
      • 2016-07-03
      • 2012-09-14
      • 1970-01-01
      相关资源
      最近更新 更多