页面加载时的十月 CMS 弹出消息

OctoberCMS Pop Up message upon page load

OctoberCMS 从这里有一个方便的弹出功能 https://octobercms.com/docs/ui/popup

虽然还有 AJAX 我从这里找到的处理程序 https://octobercms.com/docs/ajax/handlers

我正在尝试在访问者访问我的网站主页时弹出消息。但是我不知道该怎么做。我想我可以使用 AJAX 处理程序来帮助它说你可以使用 onInit() 但我没能做到。有没有正确简单的方法来做这样的事情?

我猜你想在user访问 first time 的网站时显示一次 them notification

是的,you don't need ajax for你可以直接使用Modal API

<!-- popup markup -->
<div class="control-popup modal fade" id="contentBasic">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <p>This is a very basic example of a popup...</p>
            </div>
        </div>
    </div>
</div>

<!-- put scripts will make sure that it add script at very bottom of body tag -->
{% put scripts %}
<script>
// we need to show popup when document is fully loaded
$(document).ready(function() {
    // check key is exist or not if exist then we dont show popup 
    if(localStorage.getItem('isPopupShown') === null){

        // if key is not exist means user landed on page first time
        $("#contentBasic").modal('show');

        // mark popup is already showed to user
        localStorage.setItem('isPopupShown',1)
    }    
});
</script>
{% endput %}

这将在页面加载后 show user popup仅限第一次)。

如果还有什么问题请评论。