需要在broswer close事件上加载aspx页面

时间:2017-11-08 04:37:00

标签: javascript c# jquery asp.net

您好我需要在broswer close事件上加载aspx页面。我尝试了以下代码。但它似乎没有用。任何人都可以帮我解决这个问题。感谢

 var clicked = false;
    function CheckBrowser() {
        if (clicked == false) {
            //Browser closed   
        } else {
            //redirected
            clicked = false;
        }
    }
    function bodyUnload() {
        alert(1);
        alert(clicked);
        if (clicked == false)//browser is closed  
        {
            alert(clicked);
            var request = GetRequest();
            request.open("POST", "..Security/Logout.aspx", false);
            //Send the proper header information along with the request
            request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            request.send();
        }
    }

    function GetRequest() {
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlhttp;
    }

2 个答案:

答案 0 :(得分:0)

而不是

<div class="col-md-6">
    <div class="text-center"><h4 class="text-success">Last 10 Investors</h4></div>
    <table class="table text-white" >
        <tbody>
            @foreach( \App\Fund::where('created_at', '>', \Carbon\Carbon::now()->subHours(24))->orderBy('id', 'DESC')->take(10)->get() as $fund)
            <tr>
                <th scope="row"></th>
                <td>{{ $fund->user_id }}</td>
                <td class="text-center text-warning">{{ $fund->total }}</td>
                <td class="text-right"><img src="https://adsok.com/img/btc.png" alt="Bitcoin"> <i><b>bitcoin</b></i><br></td><br>
            </tr>@endforeach

        </tbody>
    </table> 
</div>

也许你可以试试

https://login.microsoftonline.com/{tenant}/oauth2/authorize?client_id={clientid}&redirect_uri=https:%2f%2flogin.microsoftonline.com%2fte%2f{tenant}%2foauth2%2fauthresp&response_type=id_token&response_mode=form_post&nonce={nonce}&state=StateProperties

答案 1 :(得分:0)

我试过了,我的问题已经解决了

var clicked = false;

    function bodyUnload() {
        alert(1);
        if (clicked == false)//browser is closed  
        {
            var request = GetRequest();
            request.open("GET", "../TestLogout.aspx", true);
            request.send();
        }
    }

    function GetRequest() {
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlhttp;
    }

由于