如何在jquery中单击锚点时限制页面刷新 [英] How to restrict page refresh while clicking anchor in jquery

查看:68
本文介绍了如何在jquery中单击锚点时限制页面刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我在我的主布局中编写了以下脚本,用于浏览器刷新和关闭..

我需要在两个场景中注销用户,以下功能运行良好..



 < script    类型  =  text / javascript >  

var refresh = ;
var success = false ;

$(document).ready(function(){
$( a,:输入)。click(function(){
refresh = false ;
});


// 浏览器刷新和关闭脚本...
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window。 attachEvent?' onbeforeunload'' < span class =code-string> beforeunload'
;

myEvent(chkevent,function(e){
if (refresh == true ){

$ .ajax(
{
type: POST
traditional: true
dataType: json
async false
url:' @ Url.Action(MyActionMethod,MyController)'


成功:函数(数据){

if (data == 成功 ){
success = true ;
}
}
});

}
});

});
< / script >





在我的内容视图中,我有如下锚标记..并点击链接,vl重定向到尊重网址..但是,当我首先抓住该链接时,它会触发存在于我的主布局中的refresh_close相关函数..我不想在单击链接时触发该函数..



这是我的主播



我需要限制调用beforeunload事件,同时克隆锚..



我怎样才能做到这一点..



在此先感谢..

亲爱的..

解决方案

(document).ready(function(){


a,:input)。click(function(){
refresh = false ;
});


// 浏览器刷新和关闭的脚本...
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent? ' onbeforeunload'' beforeunload';

myEvent(chkevent,function(e){
if (refresh == true ){


.ajax(
{
type: POST
traditional: true
dataType: json
async false
url:' @ Url.Action(MyActionMethod, MyController)'


成功:函数(数据){

如果(data == 成功){
success = true ;
}
}
});

}
});

});
< / script >





在我的内容视图中,我有如下锚标记..并点击链接,vl重定向到尊重网址..但是,当我首先抓住该链接时,它会触发存在于我的主布局中的refresh_close相关函数..我不想在单击链接时触发该函数..



这是我的主播



我需要限制调用beforeunload事件,同时克隆锚..



我怎样才能做到这一点..



在此先感谢..

亲爱的..


Hi.. I wrote the below script in my master layout for browser refresh and close..
I need to log out the user in both scenarios and below function works well..

<script type="text/javascript">

    var refresh = true;
    var success = false;

    $(document).ready(function () {
        $("a,:input").click(function () {
            refresh = false;
        });


        //Script for Browser refresh and close...
        var myEvent = window.attachEvent || window.addEventListener;
        var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';

        myEvent(chkevent, function (e) {
            if (refresh == true) {

                $.ajax(
                {
                    type: "POST",
                    traditional: true,
                    dataType: "json",
                    async: false,
                    url: '@Url.Action("MyActionMethod", "MyController")',


                        success: function (data) {

                            if (data == "Success") {
                                success = true;
                            }
                        }
                    });

                }
            });

        });
</script>



In my content view i have the anchor tag like follows.. and clicking the link it vl redirect to respected url.. But when I m cliking that link first it fires the refresh_close related function which exist in my master layout.. I don't want to fire that function when clicking the link..

This is my anchor

I need to restrict calling beforeunload event while cliking anchor..

How can I accomplish this..

Thanks in Advance..
Honey..

解决方案

(document).ready(function () {


("a,:input").click(function () { refresh = false; }); //Script for Browser refresh and close... var myEvent = window.attachEvent || window.addEventListener; var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; myEvent(chkevent, function (e) { if (refresh == true) {


.ajax( { type: "POST", traditional: true, dataType: "json", async: false, url: '@Url.Action("MyActionMethod", "MyController")', success: function (data) { if (data == "Success") { success = true; } } }); } }); }); </script>



In my content view i have the anchor tag like follows.. and clicking the link it vl redirect to respected url.. But when I m cliking that link first it fires the refresh_close related function which exist in my master layout.. I don't want to fire that function when clicking the link..

This is my anchor

I need to restrict calling beforeunload event while cliking anchor..

How can I accomplish this..

Thanks in Advance..
Honey..


这篇关于如何在jquery中单击锚点时限制页面刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆