javascript - Open iframe page in its parent when a direct link is to one of the child pages -


hi have multiple pages reside in iframe , them open in parent page when search engine indexes them or people directly link them.

example: -this page parent page , have iframe -this first page.php -then there second page.php, third page.php, fourth page.php, ect.

i if linked of pages require iframe load parent page iframe , load url iframe. if links third page load parent page , load third page in iframe.

i have tried following scripts have found posts across web load parent page original src in frame.

<script language='javascript'>     try {          if (top == self) {             top.location.href = 'parent page.php';          }      } catch(er) { }  </script> 

and

<script type="text/javascript">     if (window == top) {         var url = 'window.location.replace("parent page.php?var1=' + window.location.href + '")';         eval(url);     } </script> 

i tried:

<body onload="refreshframe();"> 

then saw post on open iframe page in parent frame (javascript) here , brings page linked , not iframe.

the pages in iframe dymanically created idk if has or not.

but nothing seems open page inside of iframe on site loads parent page original src first page in it. idk if possible either javascript or php.

also idk if knows how practice effects seo there not many words , no tags on parent page curious too.

thanks

did try use base tag in iframe pages? like:

<base target="_parent" /> 

update

ok, in scenario need know if current page loaded on brownser or via iframe. , if it's not on iframe, redirect page calling iframe.

first thing first, check if current page inside iframe js:

<script type="text/javascript">     if ( self === top ) {         //its not iframe;     } </script> 

now know if page isn't load via iframe can use redirect inside if statament:

window.top.location="http://www.yourdomain.com"; 

now need make sure after redirect page, iframe src attribute same url before. i'm assuming can parameter int url? let me know if find trouble in part.

update2

just add parameter in url mentioned above. this:

<script type="text/javascript">     if ( self === top ) {         //its not iframe, needs redirect:         var url = window.location;         window.location="http://www.yourdomain.com/index.php?iframe="+url;     } </script> 

now in index.php ( or whatever page contain iframe):

<?php     $iframe_url = (isset($_get['iframe']) && !empty($_get['iframe'])) ? $_get['iframe'] : "initial-url-content"; ?>  <iframe src="<?=$iframe_url?>"></iframe> 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -