当用户使用php访问我的网站主页时,如何自动弹出图像?

当用户使用php访问我的网站主页时,如何自动弹出图像?,php,image,popup,Php,Image,Popup,我想一个图像自动弹出时,有人到我们的网站主页。用户可以通过点击关闭按钮来关闭它。当用户单击“关闭”时,将显示正常主页。有人能告诉我如何使用PHP实现这一点吗?谢谢你 您可以通过使用javascript实现这一点 我想你可能需要展示一个通知或广告。 然后,最好使用css模式,而不是弹出新窗口 见下文 css模态- /*模态(背景)*/ .莫代尔{ 显示:无;/*默认情况下隐藏*/ 位置:固定;/*保持原位*/ z指数:1;/*位于顶部*/ 填充顶部:100px;/*框的位置*/ 左:0; 排名:

我想一个图像自动弹出时,有人到我们的网站主页。用户可以通过点击关闭按钮来关闭它。当用户单击“关闭”时,将显示正常主页。有人能告诉我如何使用PHP实现这一点吗?谢谢你

您可以通过使用javascript实现这一点

我想你可能需要展示一个通知或广告。 然后,最好使用css模式,而不是弹出新窗口

见下文

  • css模态-

    
    /*模态(背景)*/
    .莫代尔{
    显示:无;/*默认情况下隐藏*/
    位置:固定;/*保持原位*/
    z指数:1;/*位于顶部*/
    填充顶部:100px;/*框的位置*/
    左:0;
    排名:0;
    宽度:100%;/*全宽*/
    高度:100%;/*全高*/
    溢出:自动;/*根据需要启用滚动*/
    背景色:rgb(0,0,0);/*回退色*/
    背景色:rgba(0,0,0,0.4);/*黑色w/不透明度*/
    }
    /*模态内容*/
    .模态内容{
    背景色:#fefe;
    保证金:自动;
    填充:20px;
    边框:1px实心#888;
    宽度:80%;
    }
    /*关闭按钮*/
    .结束{
    颜色:#AAAAA;
    浮动:对;
    字号:28px;
    字体大小:粗体;
    }
    .关闭:悬停,
    .结束:聚焦{
    颜色:#000;
    文字装饰:无;
    光标:指针;
    }
    模态示例
    开放模态
    &时代;
    模态中的一些文本

    //获取模态 var modal=document.getElementById('myModal'); //获取打开模式对话框的按钮 var btn=document.getElementById(“myBtn”); //获取关闭模态的元素 var span=document.getElementsByClassName(“关闭”)[0]; //当用户单击该按钮时,打开模式对话框 btn.onclick=函数(){ modal.style.display=“块”; } //当用户单击(x)时,关闭模式对话框 span.onclick=函数(){ modal.style.display=“无”; } //当用户单击模式之外的任何位置时,将其关闭 window.onclick=函数(事件){ 如果(event.target==模态){ modal.style.display=“无”; } }
  • 打开新窗口-

    
    单击该按钮可打开一个新的浏览器窗口

    试试看 函数myFunction(){ 窗口打开(“https://www.w3schools.com"); }

  • 您可以在加载文档时打开模型

    <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">
    
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
          </div>
          <div class="modal-body">
            Any Image
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    
    
    <script type="text/javascript" src="https://getbootstrap.com/docs/3.3/dist/js/bootstrap.min.js">
    <script type="text/javascript">
        $(document).ready(function() {
            $('#myModal').modal('show');
        });
    </script>
    
    
    &时代;
    模态头
    任何图像
    接近
    $(文档).ready(函数(){
    $('myModal').modal('show');
    });
    

    请向我们展示您所做的尝试,我们将尽力帮助您。另外,请更正拼写错误,以便更清楚。请不要发布仅是指向外部资源的链接的答案。如果链接断开,那么您的答案将无效。鼓励发布指向其他资源的链接,但您也应该在帖子中包含来自该外部资源或其他资源的相关信息。请查看了解更多关于为什么这通常是不赞成的,并且可以被认为是离题的。这需要,OP没有提到“当然”吗?但是在你的回答中或问题中都没有提到它。你可以检查JSFIDLE,我已经添加了外部javascript。是的,我知道这需要引导,只是看一下,我的观点是,答案中甚至问题中都没有提到它,这意味着OP可能没有寻找框架解决方案。我现在要加上它。谢谢你的建议。:)
    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to open a new browser window.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <script>
    function myFunction() {
        window.open("https://www.w3schools.com");
    }
    </script>
    
    </body>
    </html>
    
    <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">
    
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
          </div>
          <div class="modal-body">
            Any Image
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    
    
    <script type="text/javascript" src="https://getbootstrap.com/docs/3.3/dist/js/bootstrap.min.js">
    <script type="text/javascript">
        $(document).ready(function() {
            $('#myModal').modal('show');
        });
    </script>