Hi,

I basically have some links on a sidebar that loads some demos i made of mine in an iframe.

I have one problem.

As these links are on a page that does not have the iframe i need to somehow tell it to first load the iframe page.

Problem i have is if i click on a link it opens my demos in a new window as it unable to find the iframe which is of course not on the same page.

I done this before with a WYSIWYG editor, basically if you tried loading the page from an iframe it would redirect to the page that had the iframe, basically meaning stopping people from viewing it directly by accessing the link.

My site is built using html, css, php.

so this is what i am basically trying to do.

Anyone help me on this please?

I hope i explained well enough it sort of hard i think to explain it.

Thanks as always
genieuk

EDIT

I think i can explain better,

the pages must load in iframe and must not be able to be accessed directly via url. So when user clicks on link in sidebar it will load the page with the iframe on it.

Recommended Answers

All 7 Replies

Try the following format in your links':

<a target="iframeName" href="iframePage.html/#iframeName/yourDemoPage.html">DEMO</a>

Hi, i already did try that and that's what make it load in a new window, i then tried _self but only difference is it it just opens in current window but not in iframe.

I have been reading that Javascript can acheive this but not sure how i would do it meaning i need to add it to a link.

thank you,
genieuk

I am managed to solve it using an if statement so basically it checks a variable if that variable is nto equal to a specific url it wont show links.

It works a treat.

Now i need to force the iframe pages to only be allowed to show in iframe and not by directly going to url.

thank you,
genieuk

That's great and you've finally solved your own issue...

You could redirect to a page on your site with an iframe, then maybe set the src in a GET in the URL.

<a href="" onclick='document.getElementByID("iframeID").src="href";'>demo</a>
<iframe frameborder='0' src='blank.html' id='iframeID'>iframe</iframe>

To add on to almostbob's post, this is what worked for me (Firefox v3.0.10):

<a href="http://www.w3.org/" target="iframeID">Redirect frame to W3.org</a><br/>
<iframe frameborder="0" src="http://www.daniweb.com/" name="iframeID" style="width:100%; height:90%;">iframe</iframe>

As for making sure the pages can only be viewed in a frame, try adding this JavaScript to all your frame pages:

if (window == window.top)
	window.location.href = "example.php?showFrame=frameContent.html";

My advice is to make your parent frame a PHP frame, and add a GET variable that, if present, will show this HTML page instead. Example:

<?php
if ($_GET['showFrame'])
	$frameURL = $_GET['showFrame'];
else
	$frameURL = "homepage.html";
?>
<iframe src="<?php echo $frameURL ?>" name="myFrame"/>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.