简体   繁体   English

如何通过 wordpress 中的最新 jquery 在引导模式弹出窗口中动态执行 hubspot 嵌入表单脚本?

[英]how to dynamically execute hubspot embed form script inside bootstrap modal popup via latest jquery in wordpress?

I have a bootstrap modal popup form in which I append Hubspot embed script based on the button that is clicked.我有一个引导模式弹出表单,其中我 append Hubspot 基于单击的按钮嵌入脚本。 The below code works perfectly before the latest jquery core update以下代码在最新的 jquery 核心更新之前完美运行

jQuery(document).ready(function($){
   
    $('.ga-modal-popup .elementor-button,#footer-email').click(function(e){
        e.preventDefault();
        var formId = 'cc3c9892-0a53-488d-9236-ce41a01bd4aee';
        var portalId = '4079114';
        if($( this ).hasClass( "elementor-button" )){
          formId = $('.ga-modal-popup').data("form-id");
          //if portal id deosn't chnage no need to  be assigned here
          portalId = $('.ga-modal-popup').data("portal-id");
        }
      $('#footer-popup .modal-body').empty();
      $('#footer-popup .modal-body').append($('<script/>', {html: "hbspt.forms.create({portalId:'"+portalId+"',formId:'"+formId+"',css:'', cssRequired: ''});"}));
      $('#footer-popup').modal('show');
    });
});

In the latest version,the issue is with this line of code $('#footer-popup.modal-body').append($('<script/>', {html: "hbspt.forms.create({portalId:'"+portalId+"',formId:'"+formId+"',css:'', cssRequired: ''});"}));在最新版本中,问题在于这行代码$('#footer-popup.modal-body').append($('<script/>', {html: "hbspt.forms.create({portalId:'"+portalId+"',formId:'"+formId+"',css:'', cssRequired: ''});"})); if i change the same line using 'eval' like this eval($("#footer-popup.modal-body").append("<script>hbspt.forms.create({portalId:'"+portalId+"',formId:'"+formId+"',css:'', cssRequired: ''});</script>").text());如果我像这样使用'eval'更改同一行eval($("#footer-popup.modal-body").append("<script>hbspt.forms.create({portalId:'"+portalId+"',formId:'"+formId+"',css:'', cssRequired: ''});</script>").text()); it works but i don't want to use eval and also i don't want to install jquery migrate plugin and use legacy jquery.Injecting script via pure js isn't working either.它有效,但我不想使用 eval,也不想安装 jquery 迁移插件并使用旧版 jquery。通过纯 js 注入脚本也不起作用。 Any insights about how to solve this issue?有关如何解决此问题的任何见解?

var newScript = document.createElement("script");
      var inlineScript = document.createTextNode("hbspt.forms.create({portalId:'"+portalId+"',formId:'"+formId+"',css:'', cssRequired: ''});");
      newScript.appendChild(inlineScript); 
      var target  = document.querySelector("#footer-popup .modal-body");
      target.appendChild(newScript);

This pure javascript solved the issue这个纯 javascript 解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过变量引导模式弹出窗口? - How to bootstrap modal popup via a variable? 如何使用JQUERY在Bootstrap Modal中创建“编辑用户”表单? - How to make an “Edit User” form inside Bootstrap Modal using JQUERY? a href 在模态弹出窗口内不起作用不是 BOOTSTRAP,不是 JQUERY - a href's not working from inside a modal popup NOT BOOTSTRAP, NOT JQUERY 使用 jquery 和 laravel 6.x 在引导程序 4 模式中弹出编辑表单时如何获取选定项目? - how to get selected items when popup edit form in bootstrap 4 modal using jquery and laravel 6.x? 如何在Symfony2的Bootstrap Modal Popup中动态显示数据 - How to display data dynamically in Bootstrap Modal Popup in Symfony2 在 laravel 中使用 jquery 验证器时,表单未在模式弹出窗口内验证 - Form not validating inside modal popup when using jquery validator in laravel 如何使用Bootstrap 3对模式内部的表单进行样式设置 - How to style form inside modal with Bootstrap 3 在wordpress网站内使用hubspot表单时,jQuery丢失 - jquery is missing when using hubspot forms inside wordpress site 用Modal替换Popup并执行PHP脚本 - Replace Popup with Modal and execute PHP script 通过jquery触发bootstrap模式 - trigger bootstrap modal via jquery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM