[英]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.