Javascript - Open page as _blank instead of pop up - javascript

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.

Related

iFrame Redirect Issue - Not Changing the page

<iframe src="http://runebet.com/" width="80%" height="65%" name="runeBetAPI"></iframe>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script>
function RegisterPage() {
window.frames["runeBetAPI"].location = "http://runebet.com/register/";
}
RegisterPage();
</script>
This doesn't seem to work/change the content..
The URL should start with http://www. to avoid a server redirection
you can access iframe contents from the same domain only read here.
You can use the following to change the source of the iframe.
function changeSource(src, frameID) {
var frame= $('#' + frameID);
if ( frame.length ) {
frame.attr('src',src);
return true;
}
return false;
}
But apparently what looks like looking into what your code is doing the url that you are redirecting to it actually opens a registration form inside modal window, which for some reason is not opening if you access it via an iframe, because if you put the url http://runebet.com/register/ directly in the iframe and load the page it will still be showing the landing page so it is redirecting but the modal is not popping up that leaves you with the last thing that you have to trigger the Register link click and that can only happen if you are in the same domain if not maybe someone else knows, i dont.
$(window.frames[0].frameElement.contentDocument).find('a[href="/register"]').trigger('click');

iframe close after submit

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.

Close child window and open link in a framed page

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.

Executing function when pop-up window with redirects inside is closed

I'm showing the pop-up window from the page. The popup has one page, which then redirects to another (LinkedIn authorization one, to be clear), and then, after the successful login, the initial authorization page is opened again.
I want to reload the parent page when the popup is closed, but cannot do this.
The code is the following:
function OpenAuthorizePopUp() {
var w = window.open("AuthorizePage.aspx", "PopUp", "width=450,height=540");
w.onunload = function () {
SubmitPage();
};
return false;
}
function SubmitPage() {
alert("SUBMIT!");
}
The issue here is that SubmitPage() function is called not when window is closed, but just after the popup is shown. I guess it's because of redirect inside the popup, and unload is raised when we move from the first page.
Is there a way to catch the actual moment when the window is closed in this case?
So the flow of the popup goes like this:
1. Your page -> 2. LinkedIn Page -> 3. Your Page
Can you change the URL that LinkedIn sends you back to (3.) ? If so, have LinkedIn send you back to a page that has window.onunload = window.parent.SubmitPage; on it.
If you can't- ie, LinkedIn always sends you back to the first page- make the third page test for a successful connection to LinkedIn and if it's present, execute window.onunload = window.parent.SubmitPage;.
A possible improvement to your idea would be to just have the "success" page call window.parent.SubmitPage(); and then window.close(); since you won't need the popup anymore.
Found the solution. Instead of accessing parent window with window.parent, wrote
opener.location.reload(true);
And it works.

javascript popup menu and redirect url

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).

Categories