Javascript 如何在IE-11上正确阅读$u会话?

Javascript 如何在IE-11上正确阅读$u会话?,javascript,php,jquery,jquery-ui,internet-explorer,Javascript,Php,Jquery,Jquery Ui,Internet Explorer,我正在执行一项任务,试图提交一份关于IE的表格: 1.-当我在page1.php上点击“提交”时,我会看到一个jQuery UI弹出对话框,然后我点击“是我接受”,它会带我到page2.php,如果我点击“后退”按钮,它会带我回到page1.php 2.-我还有一个名为“inProgress”的php会话,当用户从page1.php转到page2.php时,该会话将赋值为1。这基本上意味着,只要用户只单击一次“Yes I accept”(是我接受)按钮,用户就不应该再显示弹出窗口(即使用户来回移

我正在执行一项任务,试图提交一份关于IE的表格:

1.-当我在page1.php上点击“提交”时,我会看到一个jQuery UI弹出对话框,然后我点击“是我接受”,它会带我到page2.php,如果我点击“后退”按钮,它会带我回到page1.php

2.-我还有一个名为“inProgress”的php会话,当用户从page1.php转到page2.php时,该会话将赋值为1。这基本上意味着,只要用户只单击一次“Yes I accept”(是我接受)按钮,用户就不应该再显示弹出窗口(即使用户来回移动)

问题:

a) 不知何故,当用户单击“提交”按钮(在page1.php上)时,弹出窗口会显示,并自动单击“是的,我接受”,但即使我返回,也不会再次出现弹出窗口,这是一件好事。然而,我更愿意自己点击“是的,我接受”按钮

b) 主要的问题是,即使我在使用IE-11时来回走动,我也会一直让弹出窗口显示出来(我只希望弹出窗口只显示一次)

我怎样才能在点击IE-11上的“Yes I accept”(是的,我接受)后让弹出窗口只显示一次,或者换句话说,我怎样才能确保会话在IE-11上被正确阅读?我考虑过用javascript来使用cookies,但不知道如何实现……请有人帮帮我。非常感谢您的先进!!这是我的page1.php和page2.php代码

page1.php

<?php
session_start();
if ($_POST) {
$_SESSION['inProgress'] = "1";
header("Location: page2.php");
exit;
}
?>
<html>
<head>
<title>Page1</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<form id="homeForm" name="homeForm" method = "POST">
<input type = "submit" id="btnOpenDialog" name = "submit">
<input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
</form>
<h1>This is Page 1</h1>
<div id="dialog-confirm"></div>
<script type="text/javascript">
$(document).ready(function(){
$("#btnOpenDialog").click(function(){
var inProgress = $('#inProgress').val();
if (inProgress !== "1") {
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
title: "Title",
height: 250,
width: 350,
closeOnEscape: false,
buttons: {
  "Yes, I accept": function () {
    $('#homeForm').submit();
    },
    "No, thanks": function () {
      $(this).dialog('close');
    }
  }
  });
  }
 });
});
</script>
</body>
</html>

第1页

在第1页,加载时,您的函数将自动运行,而不是等待用户操作。您可以将
更改为普通按钮,然后触发您的功能

它可能是这样的:

<?php
session_start();
if ($_POST) {
$_SESSION['inProgress'] = "1";
header("Location: page2.php");
exit;
}
?>
<html>
<head>
<title>Page1</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<form id="homeForm" name="homeForm" method = "POST">
<input type = "button" id="btnOpenDialog" name = "submit" onclick="yourfunctionABC()">
<input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
</form>
<h1>This is Page 1</h1>
<div id="dialog-confirm"></div>
<script type="text/javascript">

function yourfunctionABC(){
 xxx}
$(document).ready(function () {
    var preventedDefaultMet = false;
    $("#btnOpenDialog").on('click', function (event) {
        var inProgress = $('#inProgress').val();
        if (inProgress !== "1") {
            if (!preventedDefaultMet) {//so when the dialog was accepted we can trigger the click event and do not enter an infinite loop of dialogs
                event.preventDefault();//to prevent the browser from making the POST call
            }
            $("#dialog-confirm").dialog({
                resizable: false,
                modal: true,
                title: "Title",
                height: 250,
                width: 350,
                closeOnEscape: false,
                buttons: {
                    "Yes, I accept": function () {
                        preventedDefaultMet = true; // set flag
                        $('#homeForm').trigger('submit');//accepted! just trigger the click! yay!
                    },
                    "No, thanks": function () {
                        $(this).dialog('close');//trigger the click
                    }
                }
            });
        }
    });
});
<form id="homeForm" name="homeForm" method = "POST">
        <input type = "submit" id="btnOpenDialog" name = "submit">
        <input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
    </form>
<script>
   // when the browser reads this it will store the value PHP printed into the javascript variable
   var someJavaScriptVar = <? echo $_POST ? true : false ;?>;
</script>
您是否确实在第2页重置了会话变量?如果没有,会话变量始终保持设置状态,因此不会显示其他弹出窗口


希望能有所帮助。

这不是浏览器的问题(我们讨论的是会话,即只读服务器端,在客户端上,您只需使用令牌即可识别您的会话)

猜测返回时服务器代码没有被执行(浏览器缓存了页面,并且只加载图像或javascript等资产)

您可以使用
localStorage
改进这种检查客户端的行为。有一些库可以写入
localStorage
,对于旧浏览器(如果您需要旧浏览器支持),比如
simplestreage.js
(在github中),可以回退到
cookies

如果使用localStorage(我将使用无回退或换行库的
localStorage
),每当单击Yes i accept按钮并转到
page2
存储标志时就会出现这种情况:

然后在
page1
中,检查您已经在进行服务器端(会话)操作,并添加以下客户端:

解决“自动”点击问题:这不是自动点击,只是对话框没有阻止表单提交。您可以这样解决它:

<?php
session_start();
if ($_POST) {
$_SESSION['inProgress'] = "1";
header("Location: page2.php");
exit;
}
?>
<html>
<head>
<title>Page1</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<form id="homeForm" name="homeForm" method = "POST">
<input type = "button" id="btnOpenDialog" name = "submit" onclick="yourfunctionABC()">
<input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
</form>
<h1>This is Page 1</h1>
<div id="dialog-confirm"></div>
<script type="text/javascript">

function yourfunctionABC(){
 xxx}
$(document).ready(function () {
    var preventedDefaultMet = false;
    $("#btnOpenDialog").on('click', function (event) {
        var inProgress = $('#inProgress').val();
        if (inProgress !== "1") {
            if (!preventedDefaultMet) {//so when the dialog was accepted we can trigger the click event and do not enter an infinite loop of dialogs
                event.preventDefault();//to prevent the browser from making the POST call
            }
            $("#dialog-confirm").dialog({
                resizable: false,
                modal: true,
                title: "Title",
                height: 250,
                width: 350,
                closeOnEscape: false,
                buttons: {
                    "Yes, I accept": function () {
                        preventedDefaultMet = true; // set flag
                        $('#homeForm').trigger('submit');//accepted! just trigger the click! yay!
                    },
                    "No, thanks": function () {
                        $(this).dialog('close');//trigger the click
                    }
                }
            });
        }
    });
});
<form id="homeForm" name="homeForm" method = "POST">
        <input type = "submit" id="btnOpenDialog" name = "submit">
        <input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
    </form>
<script>
   // when the browser reads this it will store the value PHP printed into the javascript variable
   var someJavaScriptVar = <? echo $_POST ? true : false ;?>;
</script>
只要把我给你的两个答案混合起来,你就应该有你想要的行为。顺便说一下,我不知道你是否做了
$\u会话['inProgress']=“1”
是有原因的,但您可以编写一些javascript并将该标志存储在浏览器内存中,如下所示:

<?php
session_start();
if ($_POST) {
$_SESSION['inProgress'] = "1";
header("Location: page2.php");
exit;
}
?>
<html>
<head>
<title>Page1</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
</head>
<body>
<form id="homeForm" name="homeForm" method = "POST">
<input type = "button" id="btnOpenDialog" name = "submit" onclick="yourfunctionABC()">
<input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
</form>
<h1>This is Page 1</h1>
<div id="dialog-confirm"></div>
<script type="text/javascript">

function yourfunctionABC(){
 xxx}
$(document).ready(function () {
    var preventedDefaultMet = false;
    $("#btnOpenDialog").on('click', function (event) {
        var inProgress = $('#inProgress').val();
        if (inProgress !== "1") {
            if (!preventedDefaultMet) {//so when the dialog was accepted we can trigger the click event and do not enter an infinite loop of dialogs
                event.preventDefault();//to prevent the browser from making the POST call
            }
            $("#dialog-confirm").dialog({
                resizable: false,
                modal: true,
                title: "Title",
                height: 250,
                width: 350,
                closeOnEscape: false,
                buttons: {
                    "Yes, I accept": function () {
                        preventedDefaultMet = true; // set flag
                        $('#homeForm').trigger('submit');//accepted! just trigger the click! yay!
                    },
                    "No, thanks": function () {
                        $(this).dialog('close');//trigger the click
                    }
                }
            });
        }
    });
});
<form id="homeForm" name="homeForm" method = "POST">
        <input type = "submit" id="btnOpenDialog" name = "submit">
        <input type="text" id="inProgress" value="<?php echo $_SESSION['inProgress'] ?>"/>
    </form>
<script>
   // when the browser reads this it will store the value PHP printed into the javascript variable
   var someJavaScriptVar = <? echo $_POST ? true : false ;?>;
</script>


@Micahel我希望会话变量始终保持设置,这是我的主要目标。但是,当我使用IE时,我无法设置会话变量:(@xpng你在IE中启用了Cookie吗?是的,我启用了Cookie。你的答案完全是我需要的。非常感谢!!