【发布时间】:2020-12-08 09:52:45
【问题描述】:
这里有人用Elementor吗?你如何通过代码触发弹出窗口?例如。
function popup_call(){
...
if(....){
//trigger the popup here...
}
}
【问题讨论】:
标签: wordpress woocommerce hook hook-woocommerce elementor
这里有人用Elementor吗?你如何通过代码触发弹出窗口?例如。
function popup_call(){
...
if(....){
//trigger the popup here...
}
}
【问题讨论】:
标签: wordpress woocommerce hook hook-woocommerce elementor
这个问题已经回答了:
// accessible on window.elementorProFrontend
elementorProFrontend.modules.popup.showPopup( { id: 123 } );
https://github.com/elementor/elementor/issues/7077#issuecomment-595570337
或尝试将弹出窗口绑定到按钮,使用 css 隐藏按钮
.yourbtn {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
}
并在 js (jquery) 中使用 click
$('.yourbtn').click();
如果第二种方法对您有帮助,请不要忘记对屏幕阅读器隐藏按钮 aria-hidden="true" 和 tabindex="-1"
【讨论】:
Uncaught TypeError: Cannot read property 'showPopup' of undefined。
functions.php 下或通过代码触发该按钮?我有一个条件语句,它只会显示它是否为真。
Elementor 的 Popup 需要注册和触发。 This 主题可能对您有所帮助。
使用wp_footer 挂钩来注册您的弹出窗口。
add_action( 'wp_footer', 'your_popup_function', 10, 5);
function your_popup_function(){
if(..assuming your condition is true..){
$popup_id = '2409'; //your Popup ID.
ElementorPro\Modules\Popup\Module::add_popup_to_location( $popup_id ); //insert the popup to the current page
?><script>
jQuery( document ).ready( function() { //wait for the page to load
/* You can do more here, this will just show the popup on refresh of page, but hey this is JQuery so you can do more things here depending on your condition to trigger the popup */
jQuery( window ).on( 'elementor/frontend/init', function() { //wait for elementor to load
elementorFrontend.on( 'components:init', function() { //wait for elementor pro to load
elementorFrontend.documentsManager.documents[<?php echo $popup_id ;?>].showModal(); //show the popup
} );
} );
} );
</script>;
<?php
}
return; //return nothing by default and do not show the popup.
}
阅读 cmets 以获得更多说明。
【讨论】:
我不知道你为什么需要代码,如果你需要在点击时打开一个弹出窗口而不在浏览器底部显示 url(就像一个标签一样工作),试试“自定义类”。
【讨论】:
对我来说,它与 Wordpress 5.7.2 和 elementor pro 3.2.1 一起工作
function popup_call(){
...
if(....){
//trigger the popup here...
echo"<script> window.onload = function() {
elementorProFrontend.modules.popup.showPopup( {id:13000}, event); }
</script>";
}
}
只需设置 ID
【讨论】:
https://github.com/sukiwp/popup-trigger-url-for-elementor-pro
您需要将弹出窗口的显示条件设置设置为您希望弹出窗口显示的页面。否则,您的弹出窗口将不会显示。
【讨论】: