gpt4 book ai didi

javascript - 在 React.js 应用程序中使用 freshdesk 反馈小部件

转载 作者:行者123 更新时间:2023-11-29 10:39:15 24 4
gpt4 key购买 nike

我正在尝试在我的 React.js 应用程序中使用 Freshdesk 的反馈小部件。我正在尝试在根组件的 componentDidMount 方法中初始化并显示小部件,如下所示

var App = React.createClass({
componentDidMount: function() {
FreshWidget.init("", {"queryString": "&widgetType=popup", "utf8": "✓", "widgetType": "popup", "buttonType": "text", "buttonText": "Support", "buttonColor": "white", "buttonBg": "#006063", "alignment": "4", "offset": "235px", "formHeight": "500px", "url": "<myfreshdeskurl>"} );
FreshWidget.show();
}
});

小部件未显示,控制台中抛出以下错误

Freshdesk Error:  TypeError: Cannot read property 'style' of null
at f (http://assets.freshdesk.com/widget/freshwidget.js:1:4741)
at http://assets.freshdesk.com/widget/freshwidget.js:1:6412
at e (http://assets.freshdesk.com/widget/freshwidget.js:1:38)
at Object.C.show (http://assets.freshdesk.com/widget/freshwidget.js:1:6392)
at React.createClass.componentDidMount (http://localhost:2345/:14673:15)
at CallbackQueue.assign.notifyAll (http://localhost:2345/:102289:22)
at ReactReconcileTransaction.ON_DOM_READY_QUEUEING.close (http://localhost:2345/:115822:26)
at ReactReconcileTransaction.Mixin.closeAll (http://localhost:2345/:119697:25)
at ReactReconcileTransaction.Mixin.perform (http://localhost:2345/:119638:16)
at batchedMountComponentIntoNode (http://localhost:2345/:113776:15)

最佳答案

您必须在 FreshWidget.init 选项对象中传递另一个属性:

FreshWidget.init("", {"loadOnEvent": 'immediate',...});

否则小部件将等待已经发生的 window.load。

另外确保在使用截图选项时等到 html2canvas 加载完成,否则你会得到另一个错误:

function showWhenHTML2CanvasIsAvailable() {
if (window.html2canvas) {
window.FreshWidget.show();
} else {
setTimeout(showWhenHTML2CanvasIsAvailable, 100);
}
}

showWhenHTML2CanvasIsAvailable();

关于javascript - 在 React.js 应用程序中使用 freshdesk 反馈小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31961560/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com