I m write code as follows:
<script type="text/javascript">
function onBack(){
window.history.forward(-1);}
<body onunload="onBack();" onpageshow="if (event.persisted) onBack();">
Its working on firefox and IE but not on google crome?
Please, Help...... :)
try this:
window.onbeforeunload = function() {
return "Are you sure?";
};
Use Jquery unload. that supported by all browser
$(window).unload(function () {
alert("byebye");
});
in safari and chrome(version 14 and above) onbeforeunload and onunload event is being ignored.
Related
I have this script in my aspx page
<script language="JavaScript" type="text/javascript">
window.onbeforeunload = function(e) {
return 'Bye now!';
};
</script>
But this is not invoked when I close the browser. I need to pop an alert asking the user to confirm. I need to do this in the aspx page using javascript. The browser I tried was mozilla firefox. Thanks
The following code should fix your issue:
(function () {
window.unloader = function(e) {
(e || window.event).returnValue = null;
return null;
};
window.addEventListener("beforeunload", window.unloader);
})();
You are not going to be able to specify a message, it is defaulted by the browser.
I have the following piece of code which works fine on PC and laptop safari , mozilla and chrome browsers but not on mobile
why and how to replace the code with other working code so that it works in the same way
<script language="JavaScript" type="text/javascript" async>
window.onbeforeunload = confirmExit;
function confirmExit()
{
document.getElementById('ControlCode').style.display = "none";
document.getElementById('ControlCode').style.visibility = "hidden";
}
</script>
I've worked on it.
I can confirm to you that to obtain equal behavior you have to bind the callback like so:
window.onbeforeunload = window.onunload = function(){
/** YOUR CODE HERE **/
};
Best if placed in top of the page, to get it executed also on page load not completed.
I want to detect the exit event on all browser, I tried this code :
<html>
<head>
<script type="text/javascript">
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
</script>
</head>
<body>
<p>
Exit your browser ....
</p>
</body>
</html>
this code works in Chrome and safari but it it does'nt work in IE 11 and Fireforx 50.0.1 ... Any ideas ?
From the MDN page following notes are being mentioned
Note also, that various mobile browsers ignore the result of the event (that is, they do not ask the user for confirmation). Firefox has a hidden preference in about:config to do the same. In essence this means the user always confirms that the document may be unloaded.
The hidden keys inside about:config can be found with the keys dom.disable_beforeunload and dom.require_user_interaction_for_beforeunload.
Your code seems fine for the rest, so it may help to look in your config files (The note mentions mobile browsers, however I have these settings on my Desktop browser as well)
Try with
window.addEventListener('beforeunload', function(evt){ ...
this is the response that I find, It work for me.
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = "\o/";
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Webkit, Safari, Chrome
});
thank you
I have HTML popup window and i want add text after opening window with spec. function:
var win = window.open('private.php', data.sender_id , 'width=300,height=400');
win.window.onload = function() {
//function for add text
//chrome and firefox fire, IE and Opera not
};
This work perfectly with Chrome and Firefox, but Opera and IE9 won't working. Please tell me
best way to do that with IE and Opera.
I try with:
$(document).ready(function(){
//function for add text
});
but same thing.
I found solution, but i wont know is there better solution then setTimeout???
Instead onload event i use:
setTimeout(function(){
//add text
},200);
index.php
function callback() {
// ...
return xxx;
}
private.php
$(document).read(function() {
var text_to_insert = window.opener.callback();
})
You may try this (tested in chrome, FF, IE but don't know about opera)
var win = window.open('private.php', data.sender_id , 'width=300,height=400');
win[win.addEventListener ? 'addEventListener' : 'attachEvent']((win.attachEvent ? 'on' : '') + 'load', myFunction, false);
function myFunction(){
win.focus();
win.document.write('loaded...');
}
You may also try DOMContentLoaded event, if it works.
DEMO.
why the following code works in safari but not in IE6 ? It opens the window but doesnt trigger the alert.
<script>
function fnOpenChild()
{
var openChild = window.open('child.htm');
openChild.onload = function() {
alert("im the child window");
};
}
</script>
<input type="button" onClick="fnOpenChild()">
Thank You
try it!
to move onload event to child.htm
I know this isn't actually an answer, but I really suggest you don't use IE6 anymore, and just go with IE8+.
Afterwards, add code that will warn the user that he/she is using an out-dated web browser. You can detect the browser version using navigator.appVersion
If you want to know why you or anyone else shouldn't use it anymore:
http://www.google.nl/#hl=nl&source=hp&biw=1024&bih=837&q=Why+IE6+must+die
Edit: Aah, I guess you fixed it, but I still suggest you take a look at the link above. :)
IE6 has some... rather interesting issues and it requires some workarounds. Have you tried googleing, "IE6 window onload"? http://www.webdeveloper.com/forum/showthread.php?t=183578 seems to have a working suggestion.
Try applying onreadystatechange as well. IE6 has some issue with onload.
openChild.onload = openChild.onreadystatechange = function() { ...
There could be two possible work-arounds:
1. Move the onload script ot the childwindow
**child.htm**
<html>
<script type="text/javascript">
window.onload = function(){
alert('im the child window');
}
</script>
<body>
....
</body>
</html>
2. Declare a function in the opener window and call it on the the child's onload
**parent.htm**
<script type="text/javascript">
function forChildWindow(params){
alert('im the child window' + params);
}
</script>
**child.htm**
<html>
<script type="text/javascript">
window.onload = function(){
var load = window.opener.forChildWindow;
var someparams = " param1";
if(load) {
load(someparams);
}
}
</script>
<body>
....
</body>
</html>