I have a link that called a pop up view named class="iframe".
I planned to setup a form inside those pop up, but my problem is i need to close those pop up after clicking submit then my original page, or my pop up background will refresh it self.
My script :
<script src="<?php echo base_url(); ?>template/popup/jquery.colorbox.js"></script>
<script type="text/javascript">
var $ = jQuery.noConflict();
$(document).ready(function(){
//Examples of how to assign the Colorbox event to elements
$(".iframe").colorbox({iframe:true, width:"50%", height:"78%"});
//Example of preserving a JavaScript event for inline calls.
$("#click").click(function(){
$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
return false;
});
});
</script>
<a class='iframe' href="#">POP UP </a>
Look into PostMessages
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
You should be able to dispatch a message from your parent page. Your window should then be able to close itself once it receives the message..
(this will work cross domain too)
Use window.open to open your popup, and save it to a variable. This variable will point to that window object. You can later call .close on this variable.
var url = 'http://yourwebsite.com/subpage-within-your-website.html';
popup_window = window.open(url);
popup_window.close();
Note: Due to Javascript's security restrictions on iframes, this will only work if called on pages that belong to the same domain. I also wrote a jsFiddle but it appears they have sandbox enabled which prevents iframe access.
This page has a working example. Source code.
Related
In my Billing CMS (WHMCS) there's a page that redirects you to another page.
The problem is that this redirected page is being opened as a Pop Up, and I'm looking for the source of it to make it open in target="blank" instead.
This is the redirect script I found in the page that originates the pop up:
<script language="javascript">
setTimeout ( "autoForward()" , 0 );
function autoForward() {
var submitForm = $("#submitfrm").find("form");
submitForm.submit();
}
</script>
Can this function trigger the Pop Up? Is there a way to change it to _blank by adding something to the code above? If not, what should I look for to find the source of this function?
Thanks!!
If you have control over that function, set the form's target
function autoForward() {
var submitForm = $("#submitfrm").find("form");
submitForm.prop('target', '_blank');
submitForm.submit();
}
Here is the documentation on target.
Trying to open a link in a framed page and close the child window. The link bellow is in a child window and when I click it opens the link in the framed page, but did not close the child window
<a target="Resultado" href="?Tela=1"
onClick="javascript:return confirm('TryMe');window.close();">
I have used a code like this to close the window... but couldn't get it to work with the above code.
<a href="javascript:window.opener='Resultado';window.close();">
Try this:
<a target="Resultado" href="?Tela=1" onclick="clickHandler(event, this);">Link</a>
And declare this:
function clickHandler(e, el) {
var choice = confirm('TryMe');
if (!choice) {
e.preventDefault();
}
window.close();
}
I wasn't sure of your original use of window.close() since it came after the return and would never execute, so it's up to you to move it to where you want.
Create another webpage on your webserver & use that as the Custom URL thankyou page for your form.
In that new webpage have just one line of code.
<body onload="javascript:window.opener.childClosed();window.close();">
--
That code will call a javascript function in the parent window and then close the child popup; you can then use that javascript function to do a redirect on your parent page.
I am not to sure where the URL of your 'Thank you for requesting...' page is, but here is some javascript to redirect to google on your parent page after the form is submitted.
function childClosed() {
window.location = "http://www.google.com/"
}
You can put that script before your closing <body> tag.
--
Hopefully I have understood your query OK, let me know if you have any questions or need any clarification on this possible solution.
-
I have made a very basic clone of your webpage & form here if you want to test out the functionality, 'Factoring Question?' is the link that contains this code.
I am trying to have the user sign in through a popup window. When they click the link to the popup window which is a php variable they can sign in. When the window closes I want it to reload the page they were originally on (the parent page).
Here is the code on the signin.php page...
<body onunload="opener.location=('')">
But all this does is make the sign in page become the page the user was on. I think I need to put something in the parentheses, but I can't figure out what goes there.
To reload a page, you can set the location property as the current value, like this:
window.location = window.location;
So for your case, you would use, literally:
onunload="window.opener.location = window.opener.location;"
You can also use the reload method of the location object:
onunload="window.opener.location.reload();"
This is the preferred method.
Also, please refer to the accepted answer for your previous question: Refreshing Parent window after closing popup
Documentation
window.location on MDN - https://developer.mozilla.org/en/DOM/window.location
window.opener on MDN - https://developer.mozilla.org/Talk:en/DOM/window.opener
echo '<script>window.opener.location.reload()</script>';
echo '<script>self.close()</script>';
It works well in all browsers.
I used Tinybox
http://sandbox.scriptiny.com/tinybox2/
to open a popup web page.
I hope when I click the links on the web page, the popup web page will close and automatically redirect to the link url I click
my javascript codes and html codes
<script type="text/javascript" src="tinybox.js"></script>
<script type="text/javascript">
function openJS(){}
function closeJS(){}
function closeAndGotoURL{
TINY.box.hide();
opener.location.href='http://www.google.com';
}
Open page2
//...below is on webpage2.html, it does not work
Click
but this looks like not to work
Instead of opener.location.href, use parent.location.href. See below:
function closeAndGotoURL {
TINY.box.hide();
parent.location.href='http://www.google.com';
}
You could also use top.location.href:
function closeAndGotoURL {
TINY.box.hide();
top.location.href='http://www.google.com';
}
Another option would be to use pure HTML. Although it wouldn't close the pop up first, it would redirect the entire window to your URL. Notice the target attribute of the anchor tag.
<a href="http://www.google.com" target="_top">
NOTE 1: Why close the pop up first? If you're redirecting the whole page, just redirect - no need to close the pop up.
NOTE 2: This will only work properly if the page that is loaded in the iframe is on the same domain as the parent window (I'm assuming that it is since you're writing the pop up code).
The issue I am having is when I try to do something like the below code, the window will be blocked by pop-up blockers. I am using getScript so that I can make cross domain requests. I am using jQuery 1.4.2 to do the below.
Example of code that will be blocked:
//Code that gets blocked by pop-up blockers
$(document).ready(function(){
$(".popup").click(function(){
$.getScript("URL_To_A_Javascript_File", function(){
window.open("dynamicURL", "_blank");
});
});
});
Example of code that gets past blockers, but doesnt get URL in time:
//This code will get past the pop-up blocker, but the var url won't be updated
//with the dynamicURL before the window.open() fires in browsers
//like safari or chrome.
$(document).ready(function(){
var url;
$(".popup").click(function(){
$.getScript("URL_To_A_Javascript_File", function(){
url = "dynamicURL";
});
window.open(url, "_blank");
});
});
How can I open a new window using a URL that is generated inside the getScript callback function, and avoid pop-up blockers?
Ok, it looks like I finally figured out how to do what I was trying to do.
This way allows me to do the pop-up with out the need for an intermediate page that handles the javascript.
var newWin;
$(document).ready(function(){
$(".popup").click(function(){
newWin = window.open();
$.getScript("URL_To_A_Javascript_File", function() {
newWin.location = "DynamicURL";
});
return false;
});
});
You can't avoid popup blockers, and let us all give thanks for that.
When your code opens a window from some event loop that's not the direct result of user action (mostly that means a "click" event), the browser assumes that the user should have a choice of whether to see the new window.
In the case of something like your "getScript", the handler that's called when the script has been gotten is in one of those kinds of non-user event loops, so the blocker rules apply.
You could, perhaps, run your "getScript" code from your new window. The browser will allow the window to be opened from that "click" handler.
Simply don't work with popup, use something like Lightbox instead.