PDA

View Full Version : force page to load in iframe?



computerwiz
05-20-2009, 01:45 PM
Hello,

I am looking for a script that works.

There seems to be so many on the interent some works and some dont.

I thought i would post here as some i dont quite understand.

Basically i have a page with an iframe that loads some webpages of mine in an iframe when user clicks on link in sidebar.

Problem is user could easily type the url to the page in iframe and view it not in iframe this is a big issue specially if for example a user clicks on a iframe page link in google and it loads not in iframe as it could confuse the user.

so basically i want a script that if user tries to load page outside the iframe it directs them to the iframe page and loads the webpage they requested in the iframe.

If someone could help.

thank you
computerwiz

computerwiz
05-20-2009, 11:40 PM
anyone please?

codeexploiter
05-21-2009, 06:52 AM
Here is one such demo

1.htm


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
var correct = true;
</script>
</head>
<body>
<iframe frameborder="0" height="250" width="500" src="2.htm" scrolling="auto"></iframe>
</body>
</html>


2.htm


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
if(typeof parent.window.correct === "undefined"){
location.href = "1.htm";
}
</script>
</head>
<body>
<h1>If you are viewing then you are viewing it in an iframe</h1>
</body>
</html>



There are two different files 1.htm and 2.htm. 2.htm file is supposed to be view only through an iframe via the 1.htm file.

Now open 1.htm file in browser you'll be able to view the content of 2.htm in the iframe. Now try to open 2.htm in your browser window, the page will be redirected to 1.htm and as a result the user can view the content of 2.htm only through an iframe.

This is just a demo from which you can achieve what you want.

Hope this helps

Poontang
05-26-2009, 05:26 PM
Hey! I was looking for this trick ;o)

But: when I open 2.htm it does, correctly, open 1.htm instead. But it opens 1.htm with the default *.htm site.

My iFrame in 1.htm:
<iframe name=target style="width:626px;height:531px" src="mainFrame.htm" allowtransparency="true" frameBorder=0></iframe>


Now, i want to target 2.htm to the NAMED iFrame (target) in 1.htm... Is that possible?

Poontang
05-29-2009, 08:29 AM
hmmmm...is this thread closed for good?