首页 > 解决方案 > 弹出式仅一次

问题描述

我使用此脚本在表单(第一页)中打开一个弹出窗口,它运行良好,但在提交表单后它再次出现在确认页面中。我希望它只出现一次:我应该在脚本中添加什么参数?

谢谢

编辑 :

此代码存在于包含表单 (myform.php) 的页面中,当提交此表单时会执行操作 [myform.php?action=confirmation],因此在该确认页面中 - 这是 (myfom.php) 过程的一部分。 php) - 弹出窗口 (timer.html) 再次出现。我使用 ./lib/jquery-1.4.4.min.js ..

    var $fb_pop = jQuery.noConflict();

    $fb_pop(document).ready(function(){
        setTimeout( function(){ $fb_pop.colorbox({href:"./timer/timer.html", iframe:true, innerWidth:"150px", height:"40%", maxHeight:"200px", fixed:true}) }, 5000 );
        $fb_pop(".fb_iframe").colorbox({iframe:true, innerWidth:"150px", height:"40%", maxHeight:"150px", fixed:true }); 
    });

标签: jquery

解决方案


当表单的提交操作重新加载页面时,弹出窗口再次出现,从而再次执行其中的 javascript 代码。仅当 url 中没有“action”参数时才执行 javascript。

<?php
if (!isset($_GET['action'])) { ?>

     var $fb_pop = jQuery.noConflict();

     $fb_pop(document).ready(function(){
        setTimeout( function(){ 
           $fb_pop.colorbox({
             href:"./timer/timer.html", 
             iframe:true, 
             innerWidth:"150px", 
             height:"40%", 
             maxHeight:"200px", 
             fixed:true}) 
         }, 5000 );
    $fb_pop(".fb_iframe").colorbox({
       iframe:true, 
       innerWidth:"150px", 
       height:"40%", 
       maxHeight:"150px", fixed:true }); 
    });    

<?php 
} ?>

编辑 1 由于您通过 include() 函数将 html 页面包含在 myform.php 中,因此请使用 javascript 进行简单检查以查看 URL 是否包含“操作”文本。

  if (window.location.href.indexOf("action") === -1) {
    // include your script here
  }

推荐阅读