PDA

View Full Version : [RESOLVED] iframe guru needed


atari37
04-13-2007, 01:48 AM
I have one index.html file with menus on the left_nav, and iframe in the body. Now, when I click on a menu item (link), it is supposed to open that page in my iframe. It works for most of the pages but one of the links open in a new window even though the target is the name of my iframe. So I looked at the source code for that page and didn't like what I saw, there's a script (see below) in there to prevent the page from opening in an iframe so my question is "How do I override this?" PLEASE help.

Note: It will be very easy to comment out the script but I don't have access to the file.

<script language="JavaScript" type="text/javascript" >
// This script makes sure that our top level frame is not within
// some unknown frame which may mess up the viewability due to it
// being smaller than we need. This would be useful if someone
// else has a link to this page within a frame window.
if (parent.location != self.location)
{
parent.location = self.location.href
}

BonRouge
04-13-2007, 02:07 AM
It's not your file. The owner of the file wants it presented in his or her frameset. It seems you're out of luck.

atari37
04-13-2007, 02:14 AM
It's not your file. The owner of the file wants it presented in his or her frameset. It seems you're out of luck.

Well, thanks for the hash words.

This is a company website i'm working on...It consists of 9 pages that monitor equipments in a datacenter. My boss wanted me to place all 9 on one page for easy access. I'm not hacking into anyone's website or anything like that. These pages are running on servers that are only internal to users in the company so I might have access to them (will find out tomorrow). Problem is that next week will be my last week with my current employer and I don't think anyone will be around to manage this websites, that's why I want to keep it as simple as possible.

BonRouge
04-13-2007, 02:41 AM
I see.

You can get around it by stripping out the javascript with php.

Here's a page called 'pageStripped':<?php
$file=file_get_contents("page.htm");
$file=preg_replace('/if.*\(parent.+}/sU','',$file);
echo $file;
?>

Here's the page:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
* {
margin:0;
padding:0;
}
body {
background-color:white;
}
</style>
<script type="text/javascript">
if (parent.location != self.location)
{
parent.location = self.location.href
}
</script>
</head>
<body>
<p>Stuff goes here.</p>
</body>
</html>


That would be the page you want to show in the iframe.

Here's your page:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
* {
margin:0;
padding:0;
}
body {
background-color:white;
}
</style>
</head>
<body>
<iframe name="iframe"></iframe>
<p><a href="pageStripped.php" target="iframe">link</a></p>
</body>
</html>


'pageStripped.php' will be the page without that little bit of javascript.

Sorry about the misunderstanding. :(

I hope that helps.

atari37
04-13-2007, 02:52 AM
Thanks, I'll give this a shot...Come to think of it, I don't think I can get access to the 9 pages. These are exactly like the pages that show up when you type in your routers ip address in a browser. I don't know of anyway of editing that...I think they are coded into the equipment. If all fails, they'll have to settle with the pop ups.

atari37
04-18-2007, 07:21 AM
BonRouge if I may bother you one more time...I finally installed php on my test machine and tried out your solution...It seems to be working 50%. I don't get the pop up of the link in a new window but then the page doesn't open in the iframe either. It just returns a blank page.

Is there something that needs to be changed in the pageStripped.php file?

Thank you


This is what my files look like: Snow is the name of the page i'm trying to open in the iframe. I replaced page.html in your php script with http://snow/
pageStripped.php:
Same as above

Index.html (sample, not entire page):
<td><iframe width="100%" name="window" height="900"
src="http://intropage/" border="0" frameborder="1" scrolling="yes"
align="left" hspace="0"
vspace="0"></iframe> </td>

<tr>
<th scope="row"><a href="pageStripped.php/" target = "window" title="Snow >Snow</a></th>

</tr

BonRouge
04-18-2007, 10:08 AM
Are you sure about the url there? http://snow/ just looks wrong. If the name of the page is 'snow', what's the extension? What's the ip address? If it's internal, it might be something more like http://192.168.1.4/snow.html

atari37
04-18-2007, 10:14 AM
The page is internal and has no real url...the dns resolves the snow name to the actual ip.

All the 9 pages can be accessed through a browser by typing the name in the address bar. ie. snow and browser opens http://snow/. This page is almost identical to the pages found on wireless routers (192.168.0.1).

The php script seems to be doing something because the popup's stopped but it doesn't open the page in the iframe either...could it be blocking the entire page and not just the javascript?

BTW...i replaced that http://snow/ with http://www.cnn.com and that didn't open either.

BonRouge
04-19-2007, 02:13 AM
Works fine for me: http://bonrouge.com/test/iframe.php

atari37
04-19-2007, 03:23 AM
Works fine for me: http://bonrouge.com/test/iframe.php

Hmm...

Does your pageStripped.php look exactly like this?

<?php
$file=file_get_contents("http://www.cnn.com");
$file=preg_replace('/if.*\(parent.+}/sU','',$file);
echo $file;
?>

and also, does cnn.com have a script preventing it from being open in a frame?

BonRouge
04-19-2007, 03:28 AM
Not exactly like that...<?php
$file=file_get_contents("http://www.cnn.com/");
$file=preg_replace('/if.*\(parent.+}/sU','',$file);
echo $file;
?>

But I doubt the extra slash is the difference.

I don't think CNN does have that bit of anti-frame javascript...

atari37
04-19-2007, 03:43 AM
Not exactly like that...<?php
$file=file_get_contents("http://www.cnn.com/");
$file=preg_replace('/if.*\(parent.+}/sU','',$file);
echo $file;
?>

But I doubt the extra slash is the difference.

I don't think CNN does have that bit of anti-frame javascript...

I found the demo page on the web, I will really appreciate it if you can use the url in the pagestripped.php page and let me know if it works.

Please check pm for url...thank you

BonRouge
04-19-2007, 03:45 AM
Well, the forum has a pm system.

atari37
04-19-2007, 03:46 AM
Well, the forum has a pm system.

First time clicked on your name, if didn't give me the option to pm but that was because i wasn't logged in yet. pm sent.

Thank you