how to close popup window from asp.net mvc - javascript

I want to close some html popup windows. I have static site, which creates popup windows. These windows have a submit button, which sends a POST request to asp mvc app. This app works well and return View() (Index page with message "Ok". And Button "Close").
When I click on Close button- nothing happens.
My code:
<body>
<button type="button" id="btn" onclick="window.parent.jQuery('#btn, #m_window').hide('slow');">Close</button>
<!-- <button type="button" id="btnFoo" onclick="$("#btnFoo, #m_frame").live("click", function(){
$("#mistake").remove();
}); ">Close form </button>
-->
</body>
m_frame- frame of popup window.
mistake- div of popup window.
Please, tell me how to close this popup window?
window.close() doesn't work.
P.S. at js script (when popup creates) I write:
$("#btn",#m_window").live("click",function(){
var p = parent;
var win = p.document.getElementById('mistake');
win.parentNode.removeChild(win);
});
But it doesn't works too.

Try this
<script>
$(document).ready(function () {
$("#displayinmodal").dialog({
autoOpen: true,
modal: true,
buttons: {
"Close": function () {
$("#displayinmodal").dialog("close");
}
}
});
});
</script>
<div id="displayinmodal">
Popup demo
</div>

You should try:
window.close();

Related

I want to open a popup window on a click and insert a button in the new window to allow closing by user

I want to open a popup window from a home page us an on click button, then in that popup, I want to place an onclick button t close the popup. I have the pop open working but can't figure out how to do the rest. Here is my code:
I have the open popup working from a button in the parent window. I need the close window button in the popup window.
<button onclick="openWin()">Open "myWindow"</button>
<button id="myBtn">Close "myWindow"</button>
<script>
var myWindow;
function openWin() {
myWindow = window.open("", "myWindow", "width=400, height=200");
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.document.getElementByID("myBtn").onclick = closeWin;
}
function closeWin() {
myWindow.close();
}
</script>
Both buttons work but both are in the parent window. Need the win.close button to be placed in the popup window.
wnd.document.write("<button id='myBtn'>Close Window</button>");
wnd.document.getElementById("myBtn").onclick =
function() {
wnd.close();
};
return false;
};

dialog modal window not closing when called from child page

I am trying to use the jQuery UI dialog as pop up window and I wanted to put another aspx page as body to the Jquery UI Dialog. here I do not want to use the Jquery button option. At the child page, I have put button which is supposed to close the modal window and refresh the parent page. Below is the code I have been trying to implement but some reason I am getting js error message. Am I missing something here ?
Parent Page : aspx page
<div>
<div id="dialog" title="This is Pop up ">
<div class="modal">
<div class="modal-body">
<iframe style="width: 100%; height: 100%;" src="childPage.aspx" runat="server" frameborder="0"></iframe>
</div>
</div>
</div>
<input type="button" value="open" id="OpenDialog"/>
</div>
Jquery code : parent page
$(function () {
var dialog
dialog = $("#dialog").dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
});
$("#OpenDialog").button().on("click", function () {
dialog.dialog("open");
});
});
Child page :
<input type="button" id="btnCloseChildPageRefreshParent" value="Close and Refresh Parent Page" />
Child Page Js code :
$(function () {
$('#btnCloseChildPageRefreshParent').on('click', function () {
refreshParent();
open(location, '_self').close();
});
function refreshParent() {
window.opener.location.reload();
}
});
This is an iframe so you need to use window.parent (see the MDN documentation here) instead of window.opener. It is not a new window, but a frame, so there is no opener.
Note that the domain of the frame and parent must match, or the call will fail due to cross-domain security restrictions.
The code sample below will print out the value of window.opener and the error generated by the call to window.parent.location.reload to illustrate this.
function log (o) {
var el = document.createElement('div');
el.innerHTML = o;
document.body.appendChild(el);
}
document.getElementById('button').onclick = function () {
//This line could be used if the domain of the frame and parent match
//window.parent.location.reload();
log('window.opener is: ' + window.opener);
try {
window.parent.location.reload();
}
catch (e) {
log('Attempted to call window.parent.location.reload(): ' + e);
}
}
<button id="button">Reload Parent</button>

do not display pop up window while navigating to another page

In my page a pop up window display of confirmation only when am going to close the browser/tab. It works for my page but it also ask while am going to navigate to another page. I want the pop up window when i close tab not while navigating to another page. Can anyone plz help me.
Here is code.
var PreventExitPop = false;
function ExitPop() {
if(PreventExitPop == false) {
PreventExitPop=true;
window.alert("hi!\n\click ok to go on next page");
var frm = document.forms['exitpopform'];
frm.action = 'deals.html';
frm.submit();
scroll(0, 0);
return "\n\n\n***************************************\n\n";
}
}
window.onbeforeunload = ExitPop;
</SCRIPT>
<form id='exitpopform' method='post' action='#'>
<input type='hidden' value='' />
</form>
Try Below Code for this.
<script type="text/javascript">
$(document).ready(function () {
$("a").click(function () {
window.onbeforeunload = null;
});
$(window).bind("beforeunload", function () {
return confirm("Do you really want to close?");
});
})
</script>
Above code will set NULL for onbeforeunload when any anchor tag is cliked throughout the website.
And if user will close browser/tab than it will raise the onbeforeunload function and it will show the popup with warning message.
For this this function you have to add JQuery reference into <head> tag of you HTML page as below.
<script src="your folder name/Javascript/jquery-1.8.2.js" type="text/javascript"></script>

Chrome extension to open a new popup url on button click in chrome browser popup window

I am tring to open a new popup url in chrome extension pop up on the onclick event of a button. In my case I have a page which will display two buttons on startup. This has been set in the useropt.html page
useropt.html
<script src="scripts/usmanager.js"></script>
<body>
<div id="btn_wrap_inner">
<button class="btn" id="signin">Sign In</button><br /><br />
<button class="btn" id="signup">Sign Up</button>
</div>
</body>
The JS file usnmanager.js has js code which has code to open a new popurl url in the popup window on the onlick event of the buttons above.
usnmanager.js
function btn_clicked(tgtUrl) {
if(tgtUrl == "signin") {
var manager_url = "signin.html";
chrome.tabs.query(
{
currentWindow: true,
active : true
}, function(openselection) {
chrome.browserAction.setPopup({
popup: manager_url
});
});
} else if(tgtUrl = "signup") {
var manager_url = "signup.html";
chrome.tabs.query(
{
currentWindow: true,
active : true
}, function(openselection) {
chrome.browserAction.setPopup({
popup: manager_url
});
});
}
}
document.addEventListener("click", function() {
document.querySelector('#signin').addEventListener('click', btn_clicked('signin'));
document.querySelector('#signup').addEventListener('click', btn_clicked('signup'));
});
But when I am clicking either of the button the popup window is not loading the new popup page as set. Please let me know what have I done wrong
I would not try to pass the string in the event handler but use an attribute of the clicked button
function btn_clicked() {
var id=this.id;
if(id == "signup") {
Also in you code you test signup twice and you only add the event handler when you click something. Instead you likely want
document.addEventListener("DOMContentLoaded", function() {

Close popup window

I have a popup window which is opened using this code:
function _openpageview(fieldid,objectid,opennew)
{
var url='/s_viewpagefield.jsp?fieldid='+fieldid+'&codedid='+objectid;
web_window = window.open(url,'_blank', 'menubar=yes,location=no,scrollbars=yes,width=800,height=600,status=no,resizable=yes,top=0,left=0,dependent=yes,alwaysRaised=yes');
web_window.opener = window;
web_window.focus();
}
How can I close that popup from within the popup?
window.close();
self.close();
web_window.close();
all did not work
An old tip...
var daddy = window.self;
daddy.opener = window.self;
daddy.close();
You can only close a window using javascript that was opened using javascript, i.e. when the window was opened using :
window.open
then
window.close
will work. Or else not.
For such a seemingly simple thing this can be a royal pain in the butt! I found a solution that works beautifully (class="video-close" is obviously particular to this button and optional)
Close this window
Your web_window variable must have gone out of scope when you tried to close the window. Add this line into your _openpageview function to test:
setTimeout(function(){web_window.close();},1000);
in my case (joomla opened popup) I had to use this:
onclick="submit(); window.parent.location.reload(false);window.parent.SqueezeBox.close();"
Hope this may help
In my case, I just needed to close my pop-up and redirect the user to his profile page when he clicks "ok" after reading some message
I tried with a few hacks, including setTimeout + self.close(), but with IE, this was closing the whole tab...
Solution :
I replaced my link with a simple submit button.
<button type="submit" onclick="window.location.href='profile.html';">buttonText</button>.
Nothing more.
This may sound stupid, but I didn't think to such a simple solution, since my pop-up did not have any form.
I hope it will help some front-end noobs like me !
try this solution
<html>
<script>
var newWindow;
function openWindow() {
newWindow = window.open("", "myWindow", "width=200,height=100");
newWindow.document.write('Close this window');
}
function closeWindow() {
newWindow.close();
}
</script>
<h3 style="color:brown"> Close Window Example </h3>
<body>
<button onclick="openWindow()">Open New Window</button>
<br><br>
<button onclick="closeWindow()">Close New Window </button>
</body>
</html>
Close a popup after print.
In the parent windows
let IframeLink = '../Sale/PriceKOT?SalesID=#(Model.SalesInfo.SalesID)&PrintTypeID=3';
var newwindow = window.open(IframeLink, "KOT Print", 'width=560,height=550,toolbar=0,menubar=0,location=0');
if (window.focus) { newwindow.focus() }
function closeThisPopUp() {
newwindow.close();
printf();
}
In the child or popup window
window.onafterprint = function (event) {
opener.closeThisPopUp();
window.close;
};
using window.close()
javascript:window.close()
Try This:
<html>
<header>
<script>
let newWebWindow;
function openPageView() {
newWebWindow = window.open("", "window", "width=200,height=100");
newWebWindow.document.write(`Close this window`);
}
function closePageView() {
newWebWindow.close();
}
</script>
</header>
<body>
<h3 style="color:brown"> Close Window Example </h3>
<button onclick="openPageView()">Open Page</button>
<button onclick="closePageView()">Close Page</button>
</body>
</html>

Categories