Iframe content depends on URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mastubbs
Forum Newbie
Posts: 1
Joined: Mon Nov 10, 2008 7:29 am

Iframe content depends on URL

Post by mastubbs »

Hi all!

This is my first post im (very) new to the world of php and im guessing its a fairly easy problem to sort out. I know a bit of HTML/javascript but i've been trying to fig out how to vary iframe content by URL. For example "http://mysite.com/page11.html?&iframe=page12.html" so that the iframe on page 11 would contain page 12. The script ive been using to get this to work is :

Code: Select all

<script type="text/javascript">
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
 
function gup( name ) {
   name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
   var regexS = "[\\?&]"+name+"=([^&#]*)";
   var regex = new RegExp( regexS );
   var results = regex.exec( window.location.href );
   if( results == null )
      return "";
   else
      return results[1];
}
 
 
addLoadEvent(function() {
       var targetURL = gup("iframe");
      document.all.myIframe.src=targetURL;
})
</script>

Problem is this script only seems to work in IE not FF. From what little i know about PHP it seems like this would be easy to do but i have no idea how. I read that you can make a php page containing

Code: Select all

 <iframe src="<?php echo $_GET["iframe"]; ?> name="iframe" id="iframe" width="100%" height="320" scrolling="no" frameborder="0">fail</iframe>

I tried this and called the page 'apge11.php' and put in the url : http://mydomain.com/page11.php?iframe=page12.php but didnt work :( i just got a 'page cannot be displayed' error in the ifamre.

can anyone help?

Thanks in advance.

Matt
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: Iframe content depends on URL

Post by novice4eva »

Your javascript worked fine, i am using mozilla firefox 2.0.0.9. Yes same can be done using PHP too, but you missed double quote

Code: Select all

 
<iframe src="<?php echo $_GET["iframe"]; ?>" name="iframe" id="iframe" width="100%" height="320" scrolling="no" frameborder="0"></iframe>
 
Post Reply