【问题标题】:Run script inside thankyou message HUBSPOT form在谢谢消息 HUBSPOT 表单中运行脚本
【发布时间】:2021-12-17 15:08:31
【问题描述】:

抱歉,如果之前有人问过这个问题,我是 HubSpot 开发的新手。

我想在 Hubspot 中添加一个脚本,感谢您的消息,以便在延迟几秒钟后显示另一个页面,

setTimeout("window.location.href='redirecturl';",15000);

但是,当我在富文本 中添加这个脚本时,它会像这样显示脚本标签。

但是,我尝试使用向模板添加附加 js 文件,但没有任何效果。

也以默认方式尝试过。

jQuery.getScript("//js.hsforms.net/forms/v2.js", function() {
    hbspt.forms.create({
        portalId: "protalid",
        formId: "formid",
        onFormSubmit: function($form) {
            setTimeout(function() {
                window.location = "targeturl";
            }, 15000);
        }
    });
});

当我在控制台中运行setTimeout("window.location.href='redirecturl';",15000); this 时,它正在工作,但没有使用任何文件或将其添加到富文本中。

【问题讨论】:

    标签: jquery forms rich-text-editor hubspot


    【解决方案1】:

    您实际上不会在感谢信息中嵌入脚本。您将在托管表单的页面中使用全局表单事件回调并在那里监听表单提交。

    window.addEventListener('message', event => {
       if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmitted') {
          setTimeout(function() {
             window.location = "targeturl";
          }, 15000);
       }
    });
         
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 2019-01-04
      相关资源
      最近更新 更多