...

View Full Version : Page back into frame



zoobie
06-11-2003, 06:37 PM
If my iframe page was found on the internet search engine by itself, how would I put it back into the index page with the found page in the iframe?

The below just points to my index...but I need the page found on the internet to be inserted also.

<script>
if (parent == self) location.replace("index.html");
</script>

I'm too rusty...Thanks :p

Choopernickel
06-11-2003, 06:43 PM
This'd be a multi-part script, probably similar to what microsoft's website does.

first, in each sub-page, I'd say

if (parent == self) location.replace("index.html?pg="+location.path);

then, in the frameset (index.html), put together a frame relocator which depends on whether there's a query string:

if (location.search && location.search.length>0){
newFrameSrc = location.search.split("?&")[0];
newFrameSrc.split("=");
if (newFrameSrc[0] == "pg")
document.frames.main.src = newFrameSrc[1];
}

Not sure how that'll do for you, but I think that's probably the road you'll be going down.

[edit: whoops, can't just relocate.]

zoobie
06-11-2003, 07:34 PM
Well, I think I'm going to need clarification of said script. For example, my frame's name on the index.html is 'sara'. One of my pages is named 'foreclosure.php'...Now...to get foreclosure.php inside 'sara' on the index.html

An example would be great...

Thanks :D

Choopernickel
06-11-2003, 07:51 PM
okay, change that line in the second piece from
document.frames.main.src = newFrameSrc[1];
to
document.frames.sara.src = newFrameSrc[1];

and paste the first bit of code into foreclosure.php (or create a new file and <script src> it.

What's happening here is that from the first snippet, the script says, "If I'm the top frame, better put me inside the frameset. Plus, I'll have to tell the frameset who I am, so the frameset can find me." The location.path property contains anything after the .com/ in your URL. Appending it on to the URL in the query string (what follows the ?) creates a value to be held in the index.htm's location.search property, which is where the next piece of script comes in.

Name-value pairs in a query string are separated by ampersands (and sometimes question marks find their ways in there), so what we want to do here is create an array (using .split()) out of this location.search variable, and claim its first member (index 0, [0] )as our variable. What we've got in that variable is now pg=foreclosure.php - we then split() it again based on the equals sign we see, which turns it into an array containing ["pg", "foreclosure.php"] as its contents. The page name is at index 1, so that's what we want to change the frame's source to.

Hope that helps.

[edited for tags. tags? sheesh.]

zoobie
06-11-2003, 10:58 PM
Still not working...I think I'm mixing apples and oranges as first, I'm testing locally...then the net. All pages are in the same folder.


Part 1

if (parent == self) location.replace("index.html?pg="+location.file:///C:/My%20Documents/Pages/Jim/Florida/);


Part 2

if (location.search && location.search.length>0){
newFrameSrc = location.search.split("?&")[0];
newFrameSrc.split("=");
if (newFrameSrc[0] == "pg","foreclosure.php")
document.frames.sara.src = newFrameSrc[1];
}


Thanks

JustAsking
06-12-2003, 01:32 AM
zoobie,

I have attached a zip file with two pages:

1. index.html - this is the frameset and has an iframe called 'sara'. Includes a js function.

2. foreclosure.php - framed page with a js function to load it into index.html

This works for me, so have a look at it and change it around if you need to. Hope it works :thumbsup:

Cheers...

zoobie
06-12-2003, 02:23 AM
Nope...Still not working...I'm testing on the net now...but even with that simple version, all I get is a blank white page...Yep...I added the onload events, too.

Part 1 in frame page(s)
<script>
<!--
function LoadFrame(){
if (parent == self) window.location.href = "index.html?foreclosure.php";
}
//-->
</script>
</head>
<body onload="LoadFrame();">


Part 2 in index.html
<script>
<!--
function setFrame() {
if(location.search) {
window.sara.location = location.search.substring(1);
}
}
//-->
</script>
</head>
<body onload="setFrame();">

I type www.host.com/foreclosure.php in the addressbar and all I get is a blank white page...

JustAsking
06-12-2003, 02:47 AM
zoobie, not sure, I tested what I did only my server and it worked. Perhaps you could supply the exact www address and I will have a look at that. Maybe worth a try I guess?

zoobie
06-12-2003, 03:10 AM
Well, it's working locally in the same folder...but not on the web. Do I need to need to use a full URL like:
if (parent == self) window.location.href = "www.site.com/index.html?foreclosure.php";
?

JustAsking
06-12-2003, 07:37 AM
I guess if all your files are in the same folder location then you can use, if (parent == self) window.location.href = "index.html?foreclosure.php";

but if the files are in different folder locations then you would need to specifiy the folder location and the filename, e.g.

if (parent == self) window.location.href = "http://www.site.com/index.html?foreclosure.php";

Give it a go, see if it works.

zoobie
06-12-2003, 07:46 AM
Ok...I finally got it to work...Thanks. I wasn't waiting for both pages to fully load. I made a faster way...

This doesn't allow the first page to load:

if (parent == self) location.replace("index.html?foreclosure.php");

Now, if we could just get the index to load this page into the frame immediately instead of waiting for the whole index to load, it would be faster yet...


function doit() {
if(location.search) {
window.sara.location = location.search.substring(1);
}
}
</script>
</head>
<body onload="doit();">


Suggestions?

Thanks :D

Choopernickel
06-12-2003, 02:10 PM
zoob, here's the answer (works on my machine, works through one of my servers), attached.

extract it and run it. based on my original script and justasking's script (combined best of both)

let us know how it works.

zoobie
06-12-2003, 09:59 PM
Sorry man...but I've never been able to get your scripts to run. :)

Choopernickel
06-12-2003, 10:06 PM
damn zoob that's a low blow

uh... what else of my scripts have you tried? seriously, i ran this one just fine locally and through an http server.

you even willing to give this one a shot?

zoobie
06-12-2003, 10:33 PM
I already did...

newLoc = "index.html?"+location.pathname;

newLoc = "index.html?"+location.foreclosure.php; doesn't work

Choopernickel
06-13-2003, 01:42 PM
zoob, the script doesn't need to be changed at all from what i downloaded.

location.pathname already contains "/foreclosure.php" as its value

that's why you can't get it to run man, you can't leave well enough alone! :p

zoobie
06-13-2003, 08:26 PM
Noooo...I tried it as it was...When it didn't work, I tried changing it...Oh well...Thanks for the explanation.

UNCLE!

Choopernickel
06-13-2003, 09:20 PM
so is there anybody that can get my version to run but me?

zoobie
06-16-2003, 12:59 AM
No...http://www.stopstart.fsnet.co.uk/smilie/laugh.gif

It's probably just caching in your browser.

No matter, I found a script that rocks...and am writing my own version of it in php. :D

Will post tomorrow for reference. :cool:

zoobie
06-16-2003, 05:52 PM
It's kinda hard to believe nobody thinks what would happen if a search engine found their pages outside of their index's iframe...but whatever. :rolleyes:

This will first check to see if the page is by itself and if it is, insert it immediately into the index's iframe without the default iframe first showing...

This goes in your iframe pages:

<script>
if (parent == self) location.replace("index.html?thispagename.html");
</script>

...and this is the index's head:

<script type="text/javascript">
function writeIframe() {
var s = location.search.substring(1);
var src = s.length?s:"defaultiframesrc.html";
document.write('<iframe name="sara" src="'+src+'" width="100%" height="100%" frameborder="0"></iframe>');
}
</script>

...and this in the index's iframe location instead of <iframe></iframe>:

<script type="text/javascript">writeIframe();</script>

Now really guys...Was this asking too much? :cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum