This is my code. When I click the close button on the child window it will display suresh on the screen but if I call popuponclick() function at the time itself suresh is getting displayed. What I do??
popuponclick = function() {
window.ChildWindow = window.open('GOLF12/shared/launchpage.html',
'popupWindow',
'width=700,height=700');
window.ChildWindow.attachEvent("onunload", OnChildWindowClose());
}
OnChildWindowClose = function() {
document.getElementById("my").innerHTML = "suresh";
window.ChildWindow = null;
};
This will likely work better on your server
It does not run if there is a popup blocker, then you will need to test if ChildWindow was opened correctly
this fiddle works, but stacksnippets fail on the popup blocking
var ChildWindow;
function popuponclick() {
ChildWindow = window.open('GOLF12/shared/launchpage.html',
'popupWindow',
'width=700,height=700');
setTimeout(function() { // we need to have the new page active
ChildWindow.addEventListener("unload",OnChildWindowClose)
},100)
}
function OnChildWindowClose() {
this.opener.document.getElementById("my").innerHTML = "suresh";
this.opener.ChildWindow = null;
};
<button onclick="popuponclick()">Click</button>
<span id="my"></span>
Related
In my project, I've added the alert box and try to close the box if the user clicks on disclose button. But I don't know why this if condition is not executed.
can anyone tells me where I did make a mistake?
window.onload = function(){
var button = document.querySelector(".close");
var successMessage = document.querySelector(".messageStackSuccess");
var messageStack = document.querySelector(".messageStackError");
// console.log(successMessage.className);
button.onclick = function () {
if (messageStack.className == "messageStackError") {
messageStack.classList.add("displayNone");
}
else if (successMessage.className == "messageStackSuccess") {
successMessage.classList.add("displayNone");
}
};
};
How can I do this with MaterializeCSS?
If a user changed something in the modal and is trying to close it (by clicking outside, Esc button, or close button on modal), I want to confirm that action.
The complete option of the modal constructor only runs after the modal is closed.
This is how I catch the user changing the modal data:
var form_changed = false;
$('.modal').find('input, textarea, checkbox').on('change', function() {
form_changed = true;
});
That doesn't seem possible out-of-the-box.
After peeking at the source code, I came up with this:
function addCloseHandler($modal, handler) {
var modal = $modal[0].M_Modal;
modal._close = modal.close;
modal.close = function () { handler(function () { modal._close(); }); };
}
Usage:
// $('.modal').modal();
addCloseHandler($('.modal'), function (close) {
form_changed ? confirm('Confirm?') && close() : close();
});
I have created some code to open a YouTube video in pop-up for a few seconds. Everything is working well with this code. All I need is to show an alert to user if he/she is going to close the pop-up window. Now the problem is that the pop-up window is not related to parent window, so how can I close it?
Here is the code I am using:
$(document).ready(function() {
var myWindow;
$("#idview").click(function() {
var vidurl = 'www.youtube.com';
counter();
myWindow = window.open(vidurl, "popupWindow", "width=600, height=400, scrollbars=yes");
});
function counter() {
var n = $('.c').attr('id');
var c = n;
$('.c').text(c);
setInterval(function() {
c++;
if (c <= 41) {
$('.c').text(c);
}
if (c == 41) {
$('.c').text(n);
}
}, 1000);
}
setInterval(function() {
myWindow.close();
}, 45000);
window.onbeforeunload = closingCode;
function closingCode() {
alert('hitme');
return null;
}
});
I just want to fire a function before closing the popup window.
if you want to fire a function before closing popup window. just call it right before closing the window.
setInterval(function() {
your_callback_function();
myWindow.close();
}, 45000);
Try this:
$(function() {
if (condition) {
window.close();
}
}
or:
if (condition){
$('dialog id').dialog('close');
}
You can do like this
myWindow = window.open(vidurl, "popupWindow", "width=600, height=400, scrollbars=yes");
myWindow.onbeforeunload = closingCode;
I have modal window where i have function setConfirmation to set modal window buttons(yes,no and ok) based on logic, now when ok button okCallback is called i want to set yes and no button back to modal window because these are default buttons.
Now when user click ok we closed modal window but yes and no blinks for fraction of secs so for that i created another function resetConfirmation that i am calling from successCallBack but (yes and no) buttons still blinks for a sec before modal window close.
How can i execute resetConfirmation function after 1 sec that will resolve the issue i think or any other suggestion will be appreciated as well ?
main.js
var setConfirmationWinButtons = function(hideYesBtn, hideNoBtn, showOkBtn) {
$scope.hideYesBtn = hideYesBtn;
$scope.hideNoBtn = hideNoBtn;
$scope.showOkBtn = showOkBtn;
};
$scope.successMessage = function(mesg) {
setConfirmationWinButtons(true, true, true);
$scope.messageText = mesg;
$scope.confirmationWin.open().center();
$scope.okCallback = $scope.successCallBack;
};
$scope.successCallBack = function() {
$scope.confirmationWin.close();
resetCofirmationWin();
};
var resetCofirmationWin = function() {
setConfirmationWinButtons(false, false, false);
};
1)
inject $timeout, then use code:
$timeout(function() {
resetConfirmationWin();
}, 1000);
2) you also can use simple timeout:
setTimeout(function() {
resetConfirmationWin();
}, 1000);
It is more perfomant, because it does not fire $scope.$apply(), but you can miss model update.
It is not recommended in style guides.
I'm currently working on a web-app in which a window is there, within which, on clicking a button a new window is created using "window.showModalDialog" function. On new window there is a link, on clicking a link a new window is created using "window.showModalDialog".
Now, the requirement is, on timeout in the child window, i want to close these windows that was created.
I tried using Window.close() function within the setTimeOut function but it only closes the top most window. please help me on this issue. Jquery solution is also welcome.
var sessionTimeout = 2;
var warningTime = 0;
var thisWarningTimer = null;
var TimeOutTimer = "";
var sDisconnectURL = "SMTime";
function startTimeoutTimer()
{
sFlag="Y";
thisWarningTimer = setInterval("popupAsk()", (sessionTimeout) * 60000);
refreshSession();
}
function refreshSession()
{
warningTime = 1;
ClearTimer();
}
function startTimeOut()
{
var TimeOutTimer = setInterval("popupAsk()", (sessionTimeout) * 60000);
}
function ClearTimer()
{
clearInterval(TimeOutTimer);
startTimeOut();
}
function popupAsk()
{
alert("Session Timeout");
location.href="SMTime/Disconnect.jsp";
}