我正在使用谷歌客户评论。它工作正常。但我的目标是,只有在我点击id =“google-review”的按钮后才会加载自动覆盖
原始代码是:
<script src="https://apis.google.com/js/platform.js?onload=renderOptIn" async defer></script>
<script>
window.renderOptIn = function() {
window.gapi.load('surveyoptin', function() {
window.gapi.surveyoptin.render(
{
"merchant_id": number,
"order_id": order_id,
"email": customer_email,
"delivery_country": delivery_country,
"estimated_delivery_date": estimated_delivery_date,
"opt_in_style": "BOTTOM_TRAY"
});
});
}
</script>
我试过了:
$("#google-review").click(function() {
window.renderOptIn = function () {
window.gapi.load('surveyoptin', function () {
window.gapi.surveyoptin.render(
{
"merchant_id": number,
"order_id": order_id,
"email": customer_email,
"delivery_country": delivery_country,
"estimated_delivery_date": estimated_delivery_date,
"opt_in_style": "BOTTOM_TRAY"
});
});
}
});
但这不起作用。叠加层根本没有加载。我怎样才能实现目标?
答案 0 :(得分:2)
尝试相反的方式。脚本源onload调用renderOptin
。然后,这将设置一个单击处理程序。实际点击执行函数内的代码:
window.renderOptIn = function() {
$("#google-review").click(function() {
window.gapi.load('surveyoptin', function() {
window.gapi.surveyoptin.render({
"merchant_id": number,
"order_id": order_id,
"email": customer_email,
"delivery_country": delivery_country,
"estimated_delivery_date": estimated_delivery_date,
"opt_in_style": "BOTTOM_TRAY"
});
});
});
}
答案 1 :(得分:0)
当你加载像这样的js时,另一个解决方案就是避免参数'onload':
puts
答案 2 :(得分:0)
对我来说这是可行的,尤其是与PHP结合
$('.send-trigger').on('click',function(){
var orderId = $(this).attr('order-id');
var custEmail = $(this).attr('customer-email');
window.gapi.load('surveyoptin', function() {
window.gapi.surveyoptin.render(
{
"merchant_id": 1234534535345354,
"order_id": orderId,
"email": custEmail,
"delivery_country": "XX",
"estimated_delivery_date": "<?= date('Y-m-d') ?>"
});
});
});