Browser close event [duplicate] - asp.net

This question already has answers here:
Fired an event in asp.net when Session expired or browser close
(2 answers)
Closed 9 years ago.
Is there any other option except javascript to fire the Session_End() event when a user directly closes the browser without log off. If I all time check that the client give request to the server or not coz I think when user closes the browser, the server gets no request. So if it is possible how can I implement it? Moreover can I always check if the user is viewing any of my pages and if not can I raise Session_End() event?

No, you can't check what the user is doing or when he closes the browser.
This would clearly violate against user and data-security rights of the user. Also such a feature would be browser-dependent and therefor hard to implement because every browser has its own interfaces and philosophies.
What you can do is to implement a function in javascript, that sends a signal to your server every minute or so, telling the server that the user is still active.
You can then store the time of the last signal of the user. That way you see that a user was inactive if you haven't received a signal in the last minute or so.

hii there is one event in javascript to find the browser close event.
but its not work with all browsers.
their is the example.
<HEAD>
<TITLE> TEST</TITLE>
</HEAD>
<script type="text/javascript">
javascript:window.history.forward(1);
var temp = true;
document.onkeydown = keyDownPress;
document.onmousedown = keyDownPress;
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
//alert(is_chrome);
if(is_chrome){
window.onbeforeunload = function(e) {
// confirmExit(e);
alert("1");
alert("2");
alert("3");
return "You are going to close?"; // you can make this dynamic, ofcourse...
}
}else{
window.onbeforeunload = confirmExit;
}
/*if (navigator.userAgent.indexOf('AppleWebKit') > -1) window.onbeforeunload = confirmExit;
else Event.observe(window, 'beforeunload', confirmExit);*/
/*
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome){
window.onbeforeunload = function(e) {
confirmExit(e);
return "Are you sure you want to leave this page ?"; // you can make this dynamic, ofcourse...
};}else{
window.onbeforeunload = confirmExit;
}*/
/* if (window.addEventListener) { // all browsers except IE before version 9
window.addEventListener ("beforeunload", OnBeforeUnLoad, false);
}
else {
if (window.attachEvent) { // IE before version 9
window.attachEvent ("onbeforeunload", OnBeforeUnLoad);
}
}
*/
/* function(e){
if(temp==true ){
alert("You are going to close");
// return null;
}
}; */
function keyDownPress(e)
{
var evt = e || window.event;
var keyPressed = evt.which || evt.keyCode;
if (keyPressed==116) {
temp=false;
return false;
}
if(evt.button==2) {
alert("For security reasons, Right click has been disabled!");
return false;
}
}
function confirmExit(e){
// alert("ok ok ");
if(temp==true ){
alert("You are going to close");
}
}
This is code is working fine in IE 8 , Mozilla FF 8
not working on Google Chorme and FF 9

Related

Xamarin.Forms UI Test - Tap Button multiple (5) times

I'm working on writing an UI-Test for my Xamarin.Forms Application.
Therefore I need to tap a button 5-times. This invokes a dialog and I need the result of the user's input to this dialog.In code I realised this by implementing an GestureRecognizer:
private bool HandleMultipleTouch()
{
if (iLastTap == null || (DateTime.Now - iLastTap.Value).Milliseconds < iToleranceInMs)
{
if (NumberOfTaps == 4)
{
NumberOfTaps = 0;
iLastTap = null;
return true;
}
else
{
NumberOfTaps++;
iLastTap = DateTime.Now;
return false;
}
}
else
{
NumberOfTaps = 0;
iLastTap = null;
return false;
}
}
Do you know any method how to use Xamarin.UITest to get the button taped 5 times in a short time?
I tried used double tap twice and one single tap, but this is not working because of the time needed to execute the taps.
I had a similar issue, where I had to tap a morse code using Xamarin.UITest and concluded that it's impossible to ensure consistent timing between taps. My solution was therefore to abandon the morse code and only check in the app whether the button was hit 5 times.

redirect chrome users in new window

I have tried this but its not what I want ....
also this code does not works
<%= Html.ActionLink("Paypal", "HowItWorksRedirect", null, new { #class = "Paypal" })%>
public ActionResult HowItWorksRedirect()
{
return Redirect("https://www.paypal-deutschland.de/sicherheit/schutzprogramme.html");
}
I want to redirect all chrome users to new window
I want to keep users on my website but also redirect them to new window... (600x800 or something like this)
How can I do that?
Opening a new window (or tab, depending on browser settings) is easy:
With a link, you can use
LINK
Or you can use JS:
window.open('http://google.com', 'Google', 'width=800, height=600');
With the help of navigator.userAgent you can get the User Agent and use a regex to find out if the user is using Chrome
if(/Chrome/.test(navigator.userAgent)) { /* CHROME USER */ }
<script>
//specify page to pop-under
var popunder="http://wow.ge/"
//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0"
//Pop-under only once per browser session? (0=no, 1=yes)
//Specifying 0 will cause popunder to load every time page is loaded
var once_per_session=0
///No editing beyond here required/////
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}
function loadpopunder(){
win2=window.open(popunder,"",winfeatures)
win2.blur()
window.focus()
}
if (once_per_session==0)
loadpopunder()
else
loadornot()
</script>
but browsers blocking that !

knockout bind doubleclick and singleclick, ignore singleclick if double click

I have a click event bound to the following ko function:
self.select = function (entity, event) {
var ctrlPressed = false;
if (event.ctrlKey) { ctrlPressed = true; }
if (!ctrlPressed) {
manager.deselectAll();
this.selected(true);
} else {
this.selected() ? this.selected(false) : this.selected(true);
}
}
It is bound like so:
data-bind="click: select, event: { dblclick: function(){alert('test');}}"
This currently works except that it fires "select" twice when you double click, which I do not want. I tried following the advice in this SO question, but when I create the singleClick() function, I get an error that "ctrlKey is not a function of undefined". So it's not passing the event properly. Further more, the doubleClick() function in the other answer there doesn't work at all. It gives an error on the "handler.call" part saying handler is not defined.
So, how can I successfully call my ko select function on singleClick but NOT on doubleclick?
I don't think this is really a knockout issue. You have at least these two options:
1. Implement some custom logic that prevents processing if a single click has started processing already
2. Prevent the double-click function altogether. JQuery has this handy handler:
$(selector).on("dblclick", function(e){
e.preventDefault(); //cancel system double-click event
});
So I technically got it to work. Here is my new singleClick function
ko.bindingHandlers.singleClick = {
init: function (element, valueAccessor, c, viewModel) {
var handler = valueAccessor(),
delay = 400,
clickTimeout = false;
$(element).click(function (event) {
if (clickTimeout !== false) {
clearTimeout(clickTimeout);
clickTimeout = false;
} else {
clickTimeout = setTimeout(function () {
clickTimeout = false;
handler(viewModel, event);
}, delay);
}
});
}
};
This passes the viewModel and event to the handler so I can still modify observables and capture ctrlKey pressed.
The binding:
data-bind="singleClick: select, event: { dblclick: function(){alert('test');}}"
The problem is that now, obviously, single clicking an item has a delay while it waits to see if it's a double click. This is an inherent and unsolvable issue, I believe, so though this technically answers my question, I will consider a completely different route (ie, no double-clicking at all in my interface)

IE8 iframe onload not firing

I'm returning the following from a controller that in all current browsers ff, chrome and IE10 results in my iframe firing it's onload event:
return new ContentResult { Content = "", ContentType = "text/html", ContentEncoding = System.Text.Encoding.Unicode };
But in IE8 it does not work, I've been working under the assumption that it was my client side code that was broken and not adding a listener on to the iframes onload event, but I'm using code from Nicholas C. Zakas:
var oIFrame = document.createElement('iframe');
oIFrame.style.display = 'none';
if(oIFrame.attachEvent)
{
oIFrame.attachEvent('onload', fnIFrameCallback);
}
else
{
oIFrame.onload = fnIFrameCallback;
}
document.body.appendChild(oIFrame);
does anyone know if IE8 requires some actual content to be returned from my controller rather than just empty Content=""
This code works fine in IE 8...
function fnIFrameCallback(){
alert("test iframe is now loaded.");
}
function loadLocalIframe(){
var oIFrame = document.createElement('iframe');
oIFrame.style.display = 'none';
if(oIFrame.attachEvent)
{
oIFrame.attachEvent('onload', fnIFrameCallback);
}
else
{
oIFrame.onload = fnIFrameCallback;
}
document.body.appendChild(oIFrame);
}

auto Focus (Hit Enter) Javascript function is working good in IE7 but not working in IE8

I used a javascript FocusChange() in my aspx page. I have couple of controls and I need Hit enter key need to move next control based on tab index. It is working good in IE7 but not working in IE8... Please help me on this..
Thanks for your help in advance. The java script is given below.
function FocusChange() {
if (window.event.keyCode == 13) {
var formLength = document.form1.length; // Get number of elements in the form
var src = window.event.srcElement; // Gets the field having focus
var currentTabIndex = src.getAttribute('tabindex'); // Gets its tabindex
// scroll through all form elements and set focus in field having next tabindex
for (var i = 0; i < formLength; i++) {
if (document.form1.elements[i].getAttribute('tabindex') == currentTabIndex + 1) {
for (var j = i; j <= formLength; j++) {
if (document.form1.elements[j].disabled == false) {
document.form1.elements[j].focus();
event.returnValue = false;
event.cancel = true;
return;
}
}
}
}
}
}
I've got the same request as you, but solved it in a different manner, just replacing the Enter for Tab
<script language="JavaScript">
document.onkeydown = myOnkeydown;
function myOnkeydown()
{
var key = window.event.keyCode;
if (key == 13) //13 is the keycode of the 'Enter' key
{window.event.keyCode = 9; //9 is the code for the 'Tab' key. Essentially replacing the Enter with the Tab.
}
}
</script>
Warning: Works in IE only.

Resources