We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Get URL from iframe

Medium Priority
1,427 Views
Last Modified: 2012-05-06
I am using a PayPal checkout for customers to pay for a service. I have the PayPal checkout page load into an iframe nicely matched with our schema. The only problem is that the redirect back to our page opens our site within the iframe.

I need to write a little PHP script that gets the URL of the page currently in the iframe. I will then need to write a condition that if it is the redirect link, it will target the parent and load that page in the parent. That way I can load the redirect into top and not into the iframe.

I know how to get the URL of the parent but not the URL of the iframe from a script on the parent.

How can I get the URL of the iframe? Can I do it all with php or do I have to use a little JavaScript?

The code below is my code that gets the URL of PHP_SELF. I need to modify it to get the URL if the iframe

<?php
$currentURL = $_SERVER['PHP_SELF'];
if ($currentURL == 'http://www.starteconome.com/wp-login.php?action=register' ) {
header('Location: http://www.starteconome.com/wp-login.php?action=register');
}
?>
 
<div style="height:850px; width:100%">
<iframe name="registerFrame" src="wp-content/themes/modern-notepad/register_1-2.php" width="100%" height="100%" scrolling="auto">
If you can see this your browser does not support iframes.
</iframe>
</div>

Open in new window

Comment
Watch Question

Vivian AranhaMobile Solution Architect

Commented:
frames['registerFrame'].location.url

Author

Commented:
Thank you! What exactly do I replace with that?

Is it:
$currentURL = frames['registerFrame'].location.url;

or

$currentURL = $_SERVER['frames['registerFrame'].location.url'];
Vivian AranhaMobile Solution Architect
Commented:

<script language='javascript'>
var valUrl = frames['registerFrame'].location.url;
</script>
 
<?
 
$currentURL = "<script>document.write(valUrl);</script>";
?>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Hmm... it returns undefined?

Author

Commented:
I changed it to the following, adding document.frames but it is still undefined:
<script type="text/javascript">
var valUrl = document.frames['registerFrame'].location.url;
</script>
 
<?php
$currentURL = "<script>document.write(valUrl);</script>";
?>

Open in new window

Vivian AranhaMobile Solution Architect

Commented:
try this

var valUrl = document.frames['registerFrame'].location.href

Author

Commented:
Still undefined. I also tried

var valUrl = document.frames['registerFrame'].location.src
iframe is not a frame so you have to get it using getElementById
add this to your iframe tag

<iframe id="registerFrame"

and use

document.getElementById('registerFrame').src

Author

Commented:
Thank you!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.