Jump to content

Accessing global vars from iframes


neridaj

Recommended Posts

Hello,

 

I have an iframe contained within a page whose source page includes a call to a function that accesses a $_GET[] superglobal. is there some sort of "parent" function I need to call to have this var accessible to the iframe calling function? The iframe src page works without relying on variables i.e., the page is populated as expected with thumbnails, however, I need to separate which thumbnails are loaded based on the $_GET[] var.

 

// iframe src - thumbs.php
<?
get_main_thumbs();
?>

// page containing iframe - portfolio.php
<div id="thumbs">
<iframe id="ifrm" name="ifrm" src="thumbs.php" scrolling="auto"
width="600" height="94" frameborder="0">
[Content for browsers that don't support iframes goes here.
Suggestion: include link to file specified in iframe src attribute.]
</iframe>
</div>

// function
function get_main_thumbs()
{
$projecttype = $_GET['pt'];
$dir = '../projects/' . $projecttype . '/';
echo $dir;
$files = scandir($dir);
foreach($files as $value) {
    	if(!in_array($value, array('.', '..'))) {
    
    		// check for folders
    		if(is_dir($dir.DIRECTORY_SEPARATOR.$value)) {

        		printf('<div class="thumb"><a href="portfolio.php?pt=%s&pn=%s" target="contents">'.
                	'<img src="' . $dir . $value . '/after/' . $value . '01.jpg" width="50" height="50" /></a></div>', $projecttype, urlencode($value));
    		}
	}
}
}

 

Thanks,

 

Jason

Link to comment
https://forums.phpfreaks.com/topic/122422-accessing-global-vars-from-iframes/
Share on other sites

Thanks for the reply. I did this which works, but when I click on the thumbnails everything is loaded into a new window.

 

function get_main_thumbs()
{
$projecttype = $_GET['pt'];
$projectname = $_GET['pn'];
$dir = '../projects/' . $projecttype . '/';
$files = scandir($dir);
foreach($files as $value) {
    	if(!in_array($value, array('.', '..'))) {
    
    		// check for folders
    		if(is_dir($dir.DIRECTORY_SEPARATOR.$value)) {

        		printf('<div class="thumb"><a href="portfolio.php?pt=%s&pn=%s" target="contents">'.
                	'<img src="' . $dir . $value . '/after/' . $value . '01.jpg" width="50" height="50" /></a></div>', $projecttype, urlencode($value));
    		}
	}
}
}

 

How can I make the link just load the data in the same browser window?

 

Thanks,

 

Jason

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.