jquery - 弹出式仅一次
问题描述
我使用此脚本在表单(第一页)中打开一个弹出窗口,它运行良好,但在提交表单后它再次出现在确认页面中。我希望它只出现一次:我应该在脚本中添加什么参数?
谢谢
编辑 :
此代码存在于包含表单 (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 });
});
解决方案
当表单的提交操作重新加载页面时,弹出窗口再次出现,从而再次执行其中的 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
}
推荐阅读
- python - 如何在子类化 keras 层/模型时正确使用`@tf.function`?
- python - 在 Python 中通过 windows api 将键盘输入发送到 Notepad++
- mysql - 使用 JOIN 时优化 SELECT 查询的性能
- r - 在一个图中绘制多个插入符号的 RFE 结果
- php - 照片未使用 php 上传到 s3 存储桶
- c++ - C++ 编译器可以优化对 at() 的调用吗?
- quartz-scheduler - 如何在 Quartz.Net 中处理工作恢复
- python - 带有 Ipywidgets 和交互式图形的 Pyqt5/Pyside 应用程序
- reactjs - 反应:useState过滤器数组不更新状态
- hibernate - 春季启动中的@Transactional