I have some dojo code as below:
<script type="text/javascript">
dojo.require("dojo.io.script");
var unload = function refreshParent(){
confirmExit();
}
dojo.addOnUnload(window, "unload");
</script>
function confirmExit()
{
var r=confirm("Are you sure you want to close the window without saving it?");
if (r==true)
{
window.returnValue=true;
window.close();
}
else
{
return false;
}
}
The scenario is: On clicking on close for a window, the dojo unload gets called which closes the window.
However, I want a dialog box which asks for confirmation about the closing and if the user hits Cancel, the closing of the window should be disposed off.
However, currently, no matter what I do, the window is getting closed.
What could be the solution to this ?
You have to return the confirmExit value
var unload = function refreshParent(e){
return confirmExit();
}
Related
I have to refresh my parent window once I am done with the changes in the popup window, for which I use :
<BODY onunload="opener.location.reload();">
But this closes my window on any event, like save, whereas I don't want to get it close. I want to close my window only by clicking window close or by clicking close button in my jsp with "Javascript".
For closing thru "Close" button.
JS :
function closeAndRefresh(){
opener.location.reload(true);
window.close();
}
Solved the problem
JS:
var myclose = false;
function ConfirmClose()
{
if (event.clientY < 0)
{
myclose=true;
}
}
function HandleOnClose()
{
if (myclose==true)
{
opener.location.href = "<%=request.getContextPath()%>parent_jsp_path";
window.close();
}
}
HTML:
<BODY onbeforeunload="ConfirmClose();" onunload="HandleOnClose();">
My client has a link on their website which opens a customer service chat window in a popup. They are seeing users clicking the chat link multiple times, which opens multiple chat sessions, and it is throwing off their stats. I need to disable the link when the chat window is opened, and restore it when the chat window has been closed. I can't modify/access child window.
The original link looks like this:
<a class="initChat" onclick="window.open('https://chatlinkhere.com','chatwindow','width=612,height=380,scrollbars=0'); return false;">
I figured the best thing to do would be to store the window.open() as a variable in a function:
function openChat() {
child = window.open('http://www.google.com', 'chatwindow', 'width=612,height=380,scrollbars=0,menubar=0');
}
and change the link HTML to
<a class="initChat" onclick="openChat();">
Note: Ideally, I'd like to detect the original onclick's value, and store it in a variable. Something like:
jQuery('.initChat').find().attr('onclick');
But I'm not sure how to store it and then call it later.
Next I need to run a check to see if the chat window is open or not:
timer = setInterval(checkChild, 500);
function checkChild() {
if (child.open) {
alert("opened");
jQuery(".initChat").removeAttr("onclick");
jQuery(".initChat").css("opacity", ".5");
clearInterval(timer);
}
if (child.closed) {
alert("closed");
jQuery(".initChat").attr('onclick', 'openChat(); checkChild();');
jQuery(".initChat").css("opacity", "1.0");
clearInterval(timer);
}
}
Note: the alerts are just there for testing.
And add the new function to the link
<a class="initChat" onclick="openChat(); checkChild();">
And once the chat window is closed, I need to restore the onclick attribute to the link (is there an easier way to do this?)
Fiddle demo is here -> http://jsfiddle.net/JkthJ/
When I check Chrome Console I'm getting error
Uncaught TypeError: Cannot read property 'open' of undefined
UPDATE
Whoever left me the answer in http://jsfiddle.net/JkthJ/2/ thank you very much it works! :)
i think you need is open pop up if already open then foucus on pop up or noyhing should happen
you can rewrite your function as
var winPop = false;
function OpenWindow(url){
if(winPop && !winPop.closed){ //checks to see if window is open
winPop.focus(); // or nothing
}
else{
winPop = window.open(url,"winPop");
}
}
just do it in a simple way. disable the mouse events on anchor link after child window open.
css
.disableEvents{
pointer-events: none;
}
js
var childWindow;
$('a').on('click',function(){
childWindow = window.open('_blank',"height:200","width:500");
$(this).addClass('disableEvents');
});
if (typeof childWindow.attachEvent != "undefined") {
childWindow.attachEvent("onunload", enableEvents);
} else if (typeof childWindow.addEventListener != "undefined") {
childWindow.addEventListener("unload", enableEvents, false);
}
enableEvents = function(){
$('a').removeClass('disableEvents');
};
update
your child window is plain html page. Do the changes in child window html code:
<html>
<head>
<script>
function myFunction()
{
window.opener.enableEvents(); //it calls enableEvents function
}
</script>
</head>
<body onunload="myFunction()">
<!--your content-->
</body>
</html>
This is what I got to finally work:
<a class="initChat" onclick="checkWin()"></a>
<script>
var myWindow;
function openWin() {
myWindow = window.open('https://www.google.com', 'chatwindow', 'width=612,height=380,scrollbars=0');
}
function checkWin() {
if (!myWindow) {
openWin();
} else {
if (myWindow.closed) {
openWin();
} else {
alert('Chat is already opened.');
myWindow.focus();
}
}
}
</script>
When a user leaves a JSP page, I need to display a confirmation with yes no button "You have unsaved changes. Do you want to leave it without saving?". If the user presses "ok", then the user goes to the page s/he is navigating to. Otherwise, if "no" is pressed, the user stays on the page. My code is here:
var formdata_original=false;
jQuery(".outConfirmPlugin").click(function () {
if (formdata_original == false) {
con();
}
return formdata_original;
});
function con() {
$.confirm({
'title':'',
'message':settings.jsMessage,
'buttons':{
'Yes':{
'class':'blue',
'action':function () {
formdata_original = true;
}
},
'No':{
'class':'gray',
'action':function () {
}
}
}
});
};
I know my error is: function "con" and "return formdata_original;" - they are not synchronized. How can i do this?
try return simple value from you function, i mean
action':function () {
return true;
}
and when you call 'con' function you will be able to write
formdata_original = con();
In this case you can not worry about sinhronize
The second option is creation global object that belongs ot window or $. So try
window["formdata_original"] = false
and in your code inside confirm dialog
window["formdata_original"]=true.
I have a link:
rename
which invokes isRename() function:
function isRename(){
var i = getCheckboxCount();
if(i==1){
showInputDialog(getCheckboxName(),'Rename', 'Enter the name of file/directory',null);
}
}
function showInputDialog(a,b,c,okFunc){
$.fn.InitInputDialog(a,b,c,okFunc);
$.fn.fadeInCommon();
};
It shows a modal window. This window has a close button.
$("#CloseInputButton").off('click'); //MY CLOSE BUTTON IN MODAL WINDOW
$("#CloseInputButton").click(function(){
fadeOutCommon();
});
$.fn.fadeOutCommon = function(){
//transition effect
$('#mask').fadeTo("slow",0.0,function(){
$(dialogID).hide();
$('#mask, .window').hide();
});
};
It works fine before I press the close button. My web page refreshes and fadeOutCommon animation doesn't work at all! I think it happens because of refreshing web page! How can I disable refreshing web page?
Thanks
Just write down return false; will do that task.
rename
function isRename(){
var i = getCheckboxCount();
if(i==1){
showInputDialog(getCheckboxName(),'Rename', 'Enter the name of file/directory',null); }
return false;
}
Also have look to
e.preventDefault() will prevent the default event from occuring, e.stopPropagation() will prevent the event from bubbling up and return false will do both.
you can put return false in your click methods
$("#CloseInputButton").click(function(){
fadeOutCommon();
return false;
});
To prevent reloading, use
window.onbeforeunload = function() { 'some function that does not reload the page' }
I am displaying a warning dialog box on window close event. If user clicks on Cancel control stays on same page or if user clicks on Okay he get navigated to desired page.
I want collect the value of dialog box means whether user have clicked on Cancel or Okay.I have written following code in external JavaScript:
$(document).ready(function()
{
window.onbeforeunload = askConfirm;
function askConfirm()
{
if (flag)
{
// Message to be displayed in Warning.
return "Your unsaved data will be lost.";
}
}
}
How can I collect the value?
<script type="text/javascript">
window.onbeforeunload = function (evt) {
return "Are you sure to close?";
}
</script>
example code
http://files.dropbox.com/u/642364/blogger/scripts/close.html
EDIT
Getting the response code from the user on window close
<body onUnload = "CheckIt ()" >
...
</body>
<script>
function CheckIt ()
{
var response = confirm ("Are you closing..");
alert (response); // do whatever for response.
}
</script>