window.close() not working on pop up with pop up - javascript

I have a Customer Info form that has anchor tag "close" that should close the current window. This customer form is being opened as pop up. The Customer form also has a search btn that when clicked it pop ups the search form that is being run by a javascript called searchOrder.js. So basically it is a pop up inside a pop up. The customer form's close btn is not working but when the reference to searchOrder.js is removed, it begins to work. Also, when the search pop up is open and I click the "close" anchor tag, it closes the search pop up but never the current window which is the customer form.
Ive tried a lot of solutions already but nothing is working. I used self.close(), window.opener.close(), made it a btn instead of a link etc.,c alled a function onclick
function closeWindow() {
var closeRef;
window.opener='x';
closeRef = window.open('','_parent','');
//or closeRef = window.open("",name);
closeRef.close();
}
heres my gsp code:
<g:form method="post" name="CustomerInfoForm" target="_parent" role="form">
<div class="id="closeLink">Close</div>
<button id="searchOrderButton" type="button" class="button" onclick="searchOrder(document.forms[0].summaryMessage.value,'summaryMessageText','${createLink(action:'searchOrder')}','${createLinkTo(dir:'images',file:'closeButton.gif')}')" value="Search Order">Check Order</button>
</g:form>
How do I make the current window (customer info ) close? tnx

You should use a function like this to close your popup window :
<g:form method="post" name="CustomerInfoForm" target="_parent" role="form">
<div class="id="closeLink">
Close
</div>
<button id="searchOrderButton" type="button" class="button" onclick="searchOrder(document.forms[0].summaryMessage.value,'summaryMessageText','${createLink(action:'searchOrder')}','${createLinkTo(dir:'images',file:'closeButton.gif')}')" value="Search Order">Check Order</button>
</g:form>
<script type="text/javascript">
function openpopup()
{
my_window = window.open("","myPopup","status=1,width=100,height=100");
}
function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
}
</script>
EDIT : Don't forget to open your popup with the openpopup() function :
Open Popup Window

You can shorten window.close() to just close() and shorten window.open() to open(). Maybe you'll find what you need here, though:
http://www.w3schools.com/js/tryit.asp?filename=try_win_closed
http://www.w3schools.com/jsref/obj_window.asp

Related

How to close the webpage on its own on clicking a button

I have a page where a <button> is kept on which onClick() event fires and redirects the new page in new tab. Meanwhile I want the parent page to close itself as soon as the <button> is clicked with opening the new page in new tab. Its basically for some security feature for the website. How can this be done?
Here is my <button>, let me know where can i correct myself.
<button formtarget="_blank" type="submit" name="submit" onClick="javascript:window.open('quiz.php?unit_id=<?php echo $fnc->encode($unit_id) ; ?>');self.close();" value="submit" class="btn btn-info" style='margin-left: 35%;margin-bottom: 10px;' ><i class="glyphicon"></i> Start Quiz</button>
you can close window by below function
function close(){
setTimeout("window.close()", 500);
}
But keep in mind that : Scripts may close only the windows that were opened by it.
The window close and open new tab
<script language="javascript">
function quitWindow(cmd)
{
if(window.open("your_new_tab_page.htm")){
if (cmd=='quit')
{
open(location, '_self').close();
}
}
return false;
}
</script>
<input type="submit" onclick="return quitWindow('quit');" value="Close This Window and open new Tab" />
If you use firefox, you should about:config by writing url bar and set
dom.allow_scripts_to_close_windows = true
otherwise does not work firefox
I think this might work.
<script>
function openWindow( url )
{
window.open(url, '_blank');
window.focus();
window.close();
}
</script>
<button onclick="javascript:openWindow(yourHref);return false;">Submit</button>
You cant close your webpage if the user clicked the link of your website from any other place other than your website, due to security reasons.

Navigate new page in same tab/window using button

I've been trying to navigate a page to another page in the same window (web browser = Google Chrome, Mozilla Firefox and Internet Explorer) using button. The steps are,
The page will popup message for confirmation.
If the user click ok, then the page will navigate to other page in the same tab/window.
If the user click cancel or x, it stays on the current page.
I have tried using
window.open("home.php","_self"); and window.location.href="home.php"; and document.location.replace("home.php"); and location.replace("home.php"); and location.assign("home.php");
but it doesn't work. How do I fix this?
<span title="Click to register the new user"><button type="submit" id="submit" onclick="myFunction()">Register User</button></span>
<script>
function myFunction() {
confirm("Proceed?");
window.open("home.php");
}
</script>
Problem seems to me is, possibly you are using form with button which leads to reload.
<button type="submit" id="submit" onclick="myFunction()">Register User</button>
Make the type="submit" to type="button". Also major browser do have popup blocker enabled where this line may fail window.open("home.php");
Small change in script as follows:
function myFunction() {
if(confirm("Proceed?")) //<--- ok/yes = true, no/cancel/close = false
location.href = "home.php";
}
Small demo:
var ask = function() {
if (confirm('Proceed ?'))
location.href = "http://espn.go.com/";
};
<button onclick="ask();">Watch ...</button>
window.location.href
is not a function . You have to use it as
window.location.href="home.php";
Updated your code and this works
<span title="Click to register the new user"><button type="submit" id="submit" onclick="myFunction()">Register User</button></span>
<script>
function myFunction() {
if( confirm("Proceed?") )
window.location.href="home.php";
}
</script>

how to close a modal window using a button click

I have a modal window but I want to set up a close function so that when the user clicks on the "button", it will close the modal window. Does anyone know how this can be achieved?
I have a link to the application so you can view it here
Below is the javascript code where it shows the function of opening the modal window and the setup function of where I want to place the code to close the modal window:
function plusbutton() {
$(".previouslink").modal();
return false;
}
function closewindow() {
return false;
}
Below is the form code where user clicks on the plus button and it displays the content within the "previouslink" div tag:
<form id="QandA" action="imageupload.php" method="post">
<h1>CREATING QUESTIONS AND ANSWERS</h1>
<table id="plus" align="center">
<tr>
<th><a onclick="return plusbutton();">
<image src="Images/plussign.jpg" width="30" height="30" alt="Look Up Previous Question" class="plusimage"/>
</a><span id="plussignmsg">(Click Plus Sign to look <br />
up Previous Questions)</span> </th>
</tr>
</table>
<div class="previouslink">
<h1>PREVIOUS QUESTIONS</h1>
<button type="button" id="close" onclick="return closewindow();">Close
</button></div>
</form>
Your Live-Example shows me, that you seem to be using SimpleModal
From the documentation:
CLOSING THE DIALOG
SimpleModal will automatically bind the close
function (using the onclick event) to any element inside the dialog
with the simplemodal-close class. In addition, you can
programmatically close the currently opened dialog by calling
$.modal.close();
Means: In your closeWindow()-Function, you could simply enter the line:
$.modal.close();
and be done.
I've used this jQuery reveal modal plugin on several sites and it has worked great for me.
Alternatively, you should check out jQuery Impromptu. I love the tour feature myself, but the modals are more likely what you are trying to accomplish.
The code from both examples will probably lead you to what you are specifically looking for :)

How to close popup and redirect a page

My site using php and i create an online quiz and the quiz show in pop up mode.
Currently when i want to redirect my page using the script below. it goes to my homepage BUT it still at the pop up mode. I want it to close the pop up and go to homepage after I click finish.
How can I do that?
<script type="text/javascript">
window.parent.location = "../../../"
</script>
You can access the window that opened a popup with the window.opener property on the popup. So, something like this should work:
window.opener.location.replace(redirectUrl);
window.close;
If you wanted to put that behavior in the onclick event on a submit button you're building like this:
echo "<input type=\"submit\"
name=\"finishattempt\"
value=\"".get_string("finishattempt", "quiz")."\"
onclick=\"$onclick\" />\n";
You'd need to assign the String window.opener.location.href='someUrl';window.close(); to the variable $onclick before echoing the submit button out.
You can try this code (used on an HTML button):
<input type="button" onclick="parent.window.opener.location='http://homepage.com'; window.close();">
And have a look at some similar threads like this one: Javascript: Close Popup, Open New Window & Redirect
[EDIT] See this article too
this way you can do it ..
<script type="text/javascript">
function close_window(){
window.opener.location = 'pop_up.php';
window.close();
}
</script>
html code..
<body>
<form method="post" name="frm_2" id="frm_2">
<input type="submit" name="btn_close" id="btn_close" onclick="return close_window();" />
</form>
</body>

javascript pop-up box

OK so I haven't messed with JavaScript in a long time but I do remember some. I have tried Google but it hasn't proved to be what i wanted.
Let's say I have a link... when you click it -- a window pop-up box appears. You can submit the form... then when you press submit! The pop-up box with the form you just filled out would close and the page you clicked the box up box would be redirected....
How would I make that happen?
Try this:
Parent page:
<script type="text/javascript">
window.name="dansMainPage";
function popWin(link) {
var w = window.open(link.href,link.target,'width=500,height=600,resizable');
return w?false:true; // if popup blocker, use the default behaviour of the link
}
</script>
<a href="pagewithform.html" target="_blank"
onClick="return popWin(this)">Pop form</a>
child page:
<form target="dansMainPage" onSubmit="setTimeout(function() { window.close() },1000)">
.
.
.

Categories

Resources