[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1388
  • Last Modified:

Get URL from iframe

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

0
Shaye Larsen
Asked:
Shaye Larsen
  • 5
  • 3
2 Solutions
 
Vivian AranhaMobile Solution ArchitectCommented:
frames['registerFrame'].location.url
0
 
Shaye LarsenAuthor Commented:
Thank you! What exactly do I replace with that?

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

or

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

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

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Shaye LarsenAuthor Commented:
Hmm... it returns undefined?
0
 
Shaye LarsenAuthor 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

0
 
Vivian AranhaMobile Solution ArchitectCommented:
try this

var valUrl = document.frames['registerFrame'].location.href
0
 
Shaye LarsenAuthor Commented:
Still undefined. I also tried

var valUrl = document.frames['registerFrame'].location.src
0
 
quincydudeCommented:
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
0
 
Shaye LarsenAuthor Commented:
Thank you!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now