Okay it seems simple enough to me, First person to solve this gets paid, first come first serve type of thing. <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/microsoft|window/i', $user_agent)) { $site= "http://www.yahoo.com"; } elseif(preg_match('/mac|os x/i', $user_agent)) { $site="http://www.google.com"; } else { $site= "http://www.bing.com"; } ?> <iframe src="<?php echo $site; ?>" </frame> Code (markup): this does exactly what I want but the iframe is just a small square, I want it to be a full page, regular whole page iframe.
$user_agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/microsoft|window/i', $user_agent)) { $site= "http://www.yahoo.com"; } elseif(preg_match('/mac|os x/i', $user_agent)) { $site="http://www.google.com"; } else { $site= "http://www.bing.com"; } ?> <iframe src="<?php echo $site; ?>" width="100%" height="100%" frameborder="0"> </frame>
<?php $useragent = $_SERVER['HTTP_USER_AGENT']; if (preg_match('|MSIE ([0-9].[0-9]{1,2})|',$useragent,$matched)) { $browser_version=$matched[1]; $browser = 'IE'; } elseif (preg_match('|Opera/([0-9].[0-9]{1,2})|',$useragent,$matched)) { $browser_version=$matched[1]; $browser = 'Opera'; } elseif(preg_match('|Firefox/([0-9\.]+)|',$useragent,$matched)) { $browser_version=$matched[1]; $browser = 'Firefox'; } elseif(preg_match('|Safari/([0-9\.]+)|',$useragent,$matched)) { $browser_version=$matched[1]; $browser = 'Safari'; } else { // browser not recognized! $browser_version = 0; $browser= 'other'; } //os if (strstr($useragent,'Win')) { $os='Win'; $site = "http://www.yahoo.com"; } else if (strstr($useragent,'Mac')) { $os='Mac'; $site = "http://google.com/" } else if (strstr($useragent,'Linux')) { $os='Linux'; } else if (strstr($useragent,'Unix')) { $os='Unix'; } else { $os='Other'; } ?> <script language="JavaScript"> <!-- function resize_iframe() { var height=window.innerWidth;//Firefox if (document.body.clientHeight) { height=document.body.clientHeight;//IE } //resize the iframe according to the size of the //window (all these should be on the same line) document.getElementById("glu").style.height=parseInt(height- document.getElementById("glu").offsetTop-8)+"px"; } // this will resize the iframe every // time you change the size of the window. window.onresize=resize_iframe; //Instead of using this you can use: // <BODY onresize="resize_iframe()"> //--> </script> <iframe id="glu" width="100%" onload="resize_iframe()" src="<?php echo $site; ?>" </frame> Code (markup):
Hello, Please try this <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/microsoft|window/i', $user_agent)) { $site= "http://www.yahoo.com"; } elseif(preg_match('/mac|os x/i', $user_agent)) { $site="http://www.google.com"; } else { $site= "http://www.bing.com"; } ?> <iframe src="<?php echo $site; ?>" width="100%" height="100%" frameborder="0" scrolling="auto" style="position: absolute;top: 0;left: 0"> </frame>
i think, my post was right with one correction the closing iframe tag try different sites for your testing, seems like yahoo or google does not allow themselves to be iframed.
yeah i have tried with diffent sites, my or else is bing which can be iframed, I tried a lot of different variations, but I am still a noob at this so I might be overlooking something.
Just firgured it out. The reason is that Google/Yahoo/Bing is sending an "X-Frame-Options: SAMEORIGIN" response header. This option prevents the browser from displaying iFrames that are not hosted on the same domain as the parent page. That means you cannot put them in an iframe. If you try with another sites, such as microsoft.com, it works fine Source: https://developer.mozilla.org/en/The_X-FRAME-OPTIONS_response_header
none worked so far. @nhc1987 the sites not the problem, I changed them all to other sites when I am testing and still doesnt work.
Are you serious? It should work if you change link to microsoft.com. As described above, except the site is intended not allowed to be framed, everything else should work. Try the code below. I changed all the links to microsoft.com website. <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/microsoft|window/i', $user_agent)) { $site= "http://www.microsoft.com"; } elseif(preg_match('/mac|os x/i', $user_agent)) { $site="http://www.microsoft.com"; } else { $site= "http://www.microsoft.com"; } ?> <iframe src="<?php echo $site; ?>" width="100%" height="100%" frameborder="0" scrolling="auto" style="position: absolute;top: 0;left: 0"> Your browser doesn't support iFrames</iframe> Edit: proof
My method works 100% check it here: http://clickadx.com/testing.php <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; if(preg_match('/microsoft|window/i', $user_agent)) { $site= "http://www.microsoft.com/"; } elseif(preg_match('/mac|os x/i', $user_agent)) { $site="http://www.google.com"; } else { $site= "http://www.bing.com"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Iframe with 100% height - atguy.com</TITLE> <META NAME="Author" CONTENT="Guy Malachi"> <META NAME="Keywords" CONTENT="100% iframe resize javascript one hundred percent "> <META NAME="Description" CONTENT=""> <script language="JavaScript"> <!-- function resize_iframe() { var height=window.innerWidth;//Firefox if (document.body.clientHeight) { height=document.body.clientHeight;//IE } document.getElementById("glu").style.height=parseInt(height-document.getElementById("glu").offsetTop-8)+"px";//resize the iframe according to the size of the window //document.getElementById("glu").height=document.body.offsetHeight-document.getElementById("glu").offsetTop-26; } /* //Here is another way to define the function (this function reloads the page whenever the user resizes the page) window.onresize= function (e) { location.reload(); }; */ window.onresize=resize_iframe; //instead of using this you can use: <BODY onresize="resize_iframe()"> //--> </script> </HEAD> <BODY style="margin:0;padding:0;float:left;width:100%;"> <iframe id='glu' width='100%' onload='resize_iframe()' frameborder="0" scrolling="auto" src="<?=$site;?>"></iframe> </BODY> </HTML> Code (markup):