Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to open new window if user close the browser or tab and it is working with window.open() method but that is not i want.

i want to open using request.Open() below is my

JavaScript
var inFormOrLink;
$('a').live('click', function () { inFormOrLink = true; });
$('form').bind('submit', function () { inFormOrLink = 

$(window).bind('beforeunload', function (eventObject) {
        var returnValue = undefined;
            if (!inFormOrLink) {
               
                // this is working but i don't want it in this manner
                var params = ['height=' + screen.height, 'width=' + screen.width + ',toolbar=yes, location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes'].join(',');
                var popup = window.open("Logout.aspx", '_blank', params);
                popup.moveTo(0, 0);
                 
                //this is not working nothing is happening here
                var request = GetRequest();
                request.open("GET", "../Logout.aspx", true);
                request.send();
            }
            eventObject.returnValue = returnValue;
            return returnValue;
        });

don't know what is wrong with it.

any help would be appreciated.
Posted
Updated 23-Dec-15 0:23am
v3

1 solution

What are you doing in your code is loading a page using some GET request. It has nothing to do with the rendering mechanism of the browser...Your browser just know nothing of that data you got after request.send...
You can add the results from that request by replacing the inner HTML of your page or any of the elements on the page, but that may will not provide the same result, as JavaScript elements will not work...
There are samples of how to render such response into the page on Google - search for it, but it would be even better to explain why you don't want to use window.open...
 
Share this answer
 
Comments
ketan chandpa 23-Dec-15 7:37am    
thanks for comment but i just want that if user close the tab or browser then the logout page will automatically open that's it.
Kornfeld Eliyahu Peter 23-Dec-15 7:41am    
That's does not explain why not to use window.open!
ketan chandpa 23-Dec-15 7:56am    
i tried too much examples of window.open() method but none of it fulfill my requirement.
because suppose i use this code window.open("pageurl", _blank) then this will open new tab it is fine when user close the tab every time.

and if user close the browse then this method goes wrong.

do u understand my question now or not?

second approach and if i use this code :

var params = ['height=' + screen.height, 'width=' + screen.width].join(',');
var popup = window.open("Home.aspx", '_blank', params);
popup.moveTo(0, 0);

then new window open without basic browser functionality and if i close this window it will open again and again.

now do u understand my question or not?
Kornfeld Eliyahu Peter 23-Dec-15 8:37am    
This - in theory - does the trick...
$(window).bind('beforeunload', function (eventObject) {
var popup = window.open("http://www.microsoft.com", '_blank');
});

BUT!
1. Most (all) modern browser will identify such opening as false and will block it
2. It will not help in case you close the browser (and not the tab only) as the process will go down
3. It is a most uncommon and disturbing behavior
4. IE has some differences (as always)...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900