Php 单击“返回”和“前进”浏览器按钮后显示Flash消息

Php 单击“返回”和“前进”浏览器按钮后显示Flash消息,php,laravel,flash-message,Php,Laravel,Flash Message,一旦从服务器收到请求,我就会显示flash消息。如果用户同时单击“返回”和“前进”按钮。。。他再次看到同样的flash消息,我认为这对用户来说是一个坏消息。。。如何解决此问题?您可以使用JavaScript将显示消息中的messageId存储在变量或(隐藏)输入字段中,以便检查消息是否已准备好显示。您可以使用JavaScript将显示消息中的messageId存储在变量或(隐藏)输入字段中,因此,您可以检查消息是否已全部就绪。这是因为浏览器帮助您加载带有缓存的页面。你可以做这些 header('

一旦从服务器收到请求,我就会显示flash消息。如果用户同时单击“返回”和“前进”按钮。。。他再次看到同样的flash消息,我认为这对用户来说是一个坏消息。。。如何解决此问题?

您可以使用JavaScript将显示消息中的messageId存储在变量或(隐藏)输入字段中,以便检查消息是否已准备好显示。

您可以使用JavaScript将显示消息中的messageId存储在变量或(隐藏)输入字段中,因此,您可以检查消息是否已全部就绪。

这是因为浏览器帮助您加载带有缓存的页面。你可以做这些

header('Cache-Control: no-store, private, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false);


@if(会话::has('message'))
&时代;关
{{Session::get('message')}
@恩迪夫

这是因为浏览器帮助您加载带有缓存的页面。你可以做这些

header('Cache-Control: no-store, private, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0, max-stale = 0', false);


@if(会话::has('message'))
&时代;关
{{Session::get('message')}
@恩迪夫

我使用以下代码解决了这个问题

  <script>
   @if(!empty(Session::get('message')))
    var popupId = "{{ uniqid() }}";
    if(!sessionStorage.getItem('shown-' + popupId)) {
        swal({
            html:
            "{{Session::get('message')}}",
            showCloseButton: true,
            showCancelButton: false,
            showConfirmButton: false,
            animation: false,
            customClass: 'animated tada',
            focusConfirm: false,
            background: '#008eb0'
        });
    }
    sessionStorage.setItem('shown-' + popupId, '1');
    @endif
</script>

@如果(!empty(Session::get('message'))
var popupId=“{{uniqid()}}”;
如果(!sessionStorage.getItem('显示-'+popupId)){
游泳({
html:
“{{Session::get('message')}}”,
showCloseButton:正确,
showCancelButton:false,
showconfixton:false,
动画:错,
customClass:“动画tada”,
focusConfirm:false,
背景:“#008eb0”
});
}
setItem('show-'+popupId,'1');
@恩迪夫

我使用以下代码解决了这个问题

  <script>
   @if(!empty(Session::get('message')))
    var popupId = "{{ uniqid() }}";
    if(!sessionStorage.getItem('shown-' + popupId)) {
        swal({
            html:
            "{{Session::get('message')}}",
            showCloseButton: true,
            showCancelButton: false,
            showConfirmButton: false,
            animation: false,
            customClass: 'animated tada',
            focusConfirm: false,
            background: '#008eb0'
        });
    }
    sessionStorage.setItem('shown-' + popupId, '1');
    @endif
</script>

@如果(!empty(Session::get('message'))
var popupId=“{{uniqid()}}”;
如果(!sessionStorage.getItem('显示-'+popupId)){
游泳({
html:
“{{Session::get('message')}}”,
showCloseButton:正确,
showCancelButton:false,
showconfixton:false,
动画:错,
customClass:“动画tada”,
focusConfirm:false,
背景:“#008eb0”
});
}
setItem('show-'+popupId,'1');
@恩迪夫

晚会迟到了,但上面提出的标题解决方案对我不起作用

相反,我使用(广泛支持)来确定用户是否通过“后退”按钮到达页面,如果是,我从flash消息容器中删除显示flash消息的代码:

<script>
        var perfEntries = performance.getEntriesByType("navigation");
        for (var i = 0; i < perfEntries.length; i++) {
            if(perfEntries[i].type === "back_forward"){ // if user has reach the page via the back button...
                document.querySelector("#flashMessageContainer").innerHTML = ""; //...delete the contents of the flash container
            }
        }
</script>

var perfEntries=performance.getEntriesByType(“导航”);
对于(变量i=0;i
“performance.getEntriesByType(“navigation”)”返回“back\u forward”,如果用户通过单击后退或前进浏览器按钮到达页面(在我的情况下,向前单击也不需要flash消息)。如果单击链接或表单提交导致重定向,则返回“导航”


归因:我在派对上晚些时候从llaaalu掐了一下,但是上面提出的标题解决方案对我不起作用

相反,我使用(广泛支持)来确定用户是否通过“后退”按钮到达页面,如果是,我从flash消息容器中删除显示flash消息的代码:

<script>
        var perfEntries = performance.getEntriesByType("navigation");
        for (var i = 0; i < perfEntries.length; i++) {
            if(perfEntries[i].type === "back_forward"){ // if user has reach the page via the back button...
                document.querySelector("#flashMessageContainer").innerHTML = ""; //...delete the contents of the flash container
            }
        }
</script>

var perfEntries=performance.getEntriesByType(“导航”);
对于(变量i=0;i
“performance.getEntriesByType(“navigation”)”返回“back\u forward”,如果用户通过单击后退或前进浏览器按钮到达页面(在我的情况下,向前单击也不需要flash消息)。如果单击链接或表单提交导致重定向,则返回“导航”


归因:我从llaaalu掐了一下

,不可能同时前后点击。我想你的意思是:首先是后退,然后是前进。这里有一个参考,同时单击后退和前进是不可能的。我想你的意思是:先向后,然后向前。这是一份推荐信