PDA

View Full Version : Force URL to open as IFrame in outside URL



MJensen
07-18-2006, 11:29 PM
Force orphan url open within outside url iFrame

--------------------------------------------------------------------------------

I am trying to force database search results (html) adress to open as an IFrame with-in an outside URL. Have tried using script I saw here, but it doesnt quite fit. This requires two scripts; one for the TOP/Parent page and another for the orphaned page. essentially redirectiing the orphan page to always open with-in the IFrame of the parent page.

I know this can be done as evidenced from prior feeds on this forum....
http://www.dynamicdrive.com/forums/s...ead.php?t=2354, also follow up at http://www.dynamicdrive.com/forums/s...36&postcount=4 and the code i've used is from there:

Parent >>>>>>>>>>>>
<script type="text/javascript">
var text = window.location.href;
function delineate(str) {
theleft = str.indexOf("=") + 1;
theright = str.indexOf("&");
return(str.substring(theleft, str.length));
}
url=delineate(text)

function refreshFrame() {
if(window.location!=url)
frames['maincontentarea'].window.location.replace(url);
}
</script></head><body><iframe onload="calcHeight();" name="maincontentarea" id="maincontentarea" align="left" align="top" width="85%" height="535" scrolling="auto" marginheight="0" src="main.htm" frameborder="0">


<script language="javascript">
// writes in the iframe
var contPage = (location.search.substring(1))? location.search.substring(1) : 'main.htm';
var myDomain = "shopmalm";
// now check to see that myDomain is part of the content page string
var contValid = contPage.search(myDomain);

if (contValid == -1)
contPage = "main.htm";
else
contPage = unescape(contPage);

</script>
FOREIGN URL ORPHAN>>>>>>>>>>>>>

<script type="text/javascript">
if (window == top) {
var url='window.location.replace("http://www.saintjohnlutheran.net/?var1='+window.location.href+'")';
eval(url);
}
</script>
My problem is that instead of forcing a orphan page 'main.htm" to open inside a (outside URL) page parent 'index.htm' , My orphah pages are seach results and look like this 'dwos-bin/dynamic2.pl?nccust=malmco&code=154253'
and upon reloading i get 'dwos-bin/dynamic2.pl?nccust=malmco&code=154253.htm' as the new iframe

I would be most greatful, if anyone knows the answer to this.

jscheuer1
07-19-2006, 03:29 AM
This looks like a huge mess. I think we need to define exactly what it is that you want to have happen. Some of the terms you are using are unfamiliar to me and perhaps not the standard terms generally in use. For example, let's take just this much:


I am trying to force database search results (html) address to open as an IFrame

This should be able to be condensed to:

I want an (html) address to open in an IFrame.

But because I'm not sure of what you are saying, I have to ask if this is really what you want, is it? Now, I know you wrote 'open as an IFrame' but, this is not really possible, 'in an IFrame' is possible, will that do?

If that much will do, all we need to know is where the iframe is and where the information as to the address is coming from and how we can capture that information and set either the iframe's href property or src attribute to the address. Sometimes it is easier or better to do one or the other, sometimes it makes no difference.

But, before I try to do all that, please answer if:

1 ) Will opening an (html) address in an IFrame do?

and, if so:

2 ) Where is the iframe or do we have to create one 'on the fly'?

3 ) Where does the address come from?

4 ) Is there more than one browser window involved?

MJensen
07-25-2006, 08:45 PM
I hope this will clarify

1. yes. opening an (html1) address in an IFrame will do.

2. The iframe does not need to be created 'on the fly'. It exists as the
maincontentarea of another 'outside' (html2) address.

3. The (html1) address to be re-directed comes from the address
generated search results of a database located within same (html1)
address. Address (html1) example: = www datadomain.html/dwos-
bin/search.pl=id?datafield1=text&datafield=text&sortdata=feild&pgdesign=
dynamicformated

4. Only one browser window for the (html1) address and only one browser
window for the (iframe) page address are involved. The (html1) address
will automatically open inside the (iframe) of the 'outside' (html2) address
as a result of the script I am searching for.

jscheuer1
07-26-2006, 04:10 AM
I'm still not clear on this, where you say:


www datadomain.html/dwos-bin/search.pl=id?datafield1=text&datafield=text&sortdata=feild&pgdesign=dynamicformated

That is neither a valid URL or a valid search string. It could be a valid search string if it was www%20datadomain except that, just as a rule of thumb, www is a poor choice as a portion of a filename which, is what it looks like it would be if the above were a search string.

Perhaps you have a typo or are trying to convey something with the colors used for the example that has gone over my head.

In any case, if this is server side code, why can't you have the server side language take the query results and convert them to a server side redirect. If this is done on a page already in an iframe, the redirect should then populate the iframe.

MJensen
07-26-2006, 03:23 PM
Well, I could perhaps do so, but it would, if i understand correctly, require re-writing code for hundreds of pages. None-the-less, you have identified what it is im looking for, and on a previous occassion provided script almost identical to another student. That thread can be found here:

http://www.dynamicdrive.com/forums/showthread.php?t=8567

The only difference is that the prior student was re-directing an (htm) into another (htm) and in this case it's a searchstring to an (htm). Can this be done?

jscheuer1
07-26-2006, 05:49 PM
If I give you a javascript to do this, I would think that 100's of pages would need to have the script on it as well then, the only difference is that it won't work in as many browsers.

Or maybe not, if a javascript can do it without editing 100's of pages, then a redirect should also be able to do it without editing 100's of pages.

The redirect would go on the page in the iframe. It would test its own query string and redirect if certain conditions are met.

But, though I am not real strong on server side languages, I seem to remember that, at least in ASP/VBscript, that a page cannot redirect on the basis of a query string because it is basically too late to do so once the query string is read.

Anyways, I didn't mean to say I wouldn't try to come up with a javascript solution for this. Just that a server side solution would be superior. As I recall no server side coding was involved in the thread you are referring to.

I just checked, it wasn't. OK then, the script information in that thread when used with the information that thread links to (added to the content and top pages) will force a page that is intended to be in an iframe into its iframe if it is navigated to individually. How is your situation different?

Additionally, if modifications are needed, I still need a better understanding of the query string you have to work with. What you have supplied so far looks to me as though it isn't a valid url. No redirection can be done in any language if the destination url isn't known.

MJensen
07-27-2006, 02:28 PM
This is where my limited script knowlege breaks down, and so I'm not sure how to respond. Perhaps knowing that the search result pages all use one teplate helps you to see why id rather re-direct the (to be) iframes.

Ok so here's what happens when i use the (htm) to (htm) script referred to in a prior thread for the query page URL>

SCRIPT LANGUAGE='javascript'>
/* try { if (top == self) {top.location.href='index.html'; } } catch(er) { } */
if (window == top) {
var url='window.location.replace("index.html?var1='+window.location.href+'")';
eval(url);
}
</SCRIPT>

I get a redirect address:

domain1.htm?var1=domain2.htm/dwos-bin/queryx.pl.nccust=malm&field1=text&field2=text&sortby=text.htm

How can i stop the addition of .htm to this address


And what script will ensure that it writes into its target iframe named="maincontentarea" on the parent page. Prof. Scheuer, thank you for staying with me..I hope im answering as consisely as possible and am most gratefull for your time....

Does this bring us to the next level?

jscheuer1
07-27-2006, 07:27 PM
Somewhat but, we may have a deal breaker. Javascript, and for that matter any server side languages as far as I know, cannot work across domains in certain situations where iframes or frames are concerned. Because this situation is different than any exact situation I've encountered before, this may not matter, we would have to try it out but, just because it might seem to be working at first doesn't mean that it might not break down as it is extended to additional page loads. The error(s) it throws (if any) would be my final guide to if this is a problem or not.

Now, I am not even sure that more than one domain is involved here but:



domain1.htm?var1=domain2.htm . . .

Seems to indicate that there might be. But, like www, domain is a poor choice of filename. If these really are domains then domain1.htm isn't a valid filename so I am back to square one, not knowing what the url really looks like.

Further, since what you seem to want is this:

You have a page inside an iframe. You click on a link on that page and want the page that is navigated to as a result to be displayed within that same iframe.

That can be achieved with an ordinary link on the page in the iframe. Perhaps you are over thinking this.

Twey
07-27-2006, 07:58 PM
and for that matter any server side languages as far as I know, cannot work across domains in certain situations where iframes or frames are concerned.Server-side languages do not have a domain restriction. Only local data that is not included in the output is unavailable when obtaining a document from another server (such as variables).

MJensen
07-27-2006, 08:07 PM
Oh :>(
I've looked at the sites where javascript was used in this scenario previously, and them seem to work without flaw. With regard to links, yes they already exist outside the maincontentarea of the TOP page.

Would it be easier if I provided the actual site addresses involved or does this work?

IFRAME PAGE URL

(DOMAIN#1).COM/INDEX.HTM

SEARCH QUERY PAGE

(DOMAIN#2).COM/DWOS-BIN/QUERYX.PL?NCCUST=MALMCO&CATEGORY=FURNITURE&NAME=DESK&SORTBY=CODE

jscheuer1
07-27-2006, 08:46 PM
With regard to links, yes they already exist outside the maincontentarea of the TOP page.

Then the straightforward method would be:


<a href="whatever" target="maincontentarea">Link Text</a>

where "maincontentarea" is the name of the iframe.

Twey
07-27-2006, 10:52 PM
You can't have anything on a different domain inside that iframe.

MJensen
07-27-2006, 11:28 PM
Twey...who says that? how 'bout this site>>>>>

http://www.aircraftjournal.com/books.htm

MJensen
07-27-2006, 11:31 PM
Professor; I must confess i'm a bit discpuraged that you're showing me how to link a page after all the time youve spent with me. Appreciate your time anyhow. Regards. MJ

Twey
07-28-2006, 12:16 AM
That site doesn't use a scroller. :)
Sorry, I'll clarify:
You can't have anything on a different domain inside that iframe if you want to use the iframe scroller.

MJensen
07-28-2006, 12:53 AM
Well far be it for me to question, but are you sure? can't is a very finite word. Is there anything you can suggest having seen what it is im looking for, perhaps you'd have an idea that might help sovle my re-direct problem.

Thx

Twey
07-28-2006, 02:19 AM
are you sure?If I weren't sure, I'd have made sure I mentioned my uncertainty, using phrases such as "I think," "if I remember correctly," or "to the best of my knowledge."

Yes, I'm sure. :)

jscheuer1
07-28-2006, 04:11 AM
I still don't have a clear idea of what the problem is here. If it was about using an iframe scroller, I must have missed when that became a part of the discussion. I have in the past worked it out where a page from another domain can be made to appear to scroll to a certain position. This involves three pages. The top page which has an iframe on it. The page inside the iframe is just a 'blank' page with a full page iframe on it that contains the page from the other domain. Using this type of scheme, the page from the other domain may be made to appear to scroll from the point of view of the top page but, it is really the intermediate page which is scrolling. All legal because the only two pages that are really communicating are both on the same domain.

I also feel that I have to say here, that this has been the vaguest or close to the vaguest question I have ever tried answering. I've seen worse but, I usually steer clear of those. Please try to be more clear about what exactly it is that you want.

MJensen
07-28-2006, 12:59 PM
Dear Prof Scheuer;

I truely am greatful for your help and am doing the best to explain..."At one point I said to the effect >>I would like exactly the same scrpt that was used in a thread dated Apr 4, 2006 given to jlorenz by yourself . The one exception being that instead on loading (htm) into the frame, i m trying to load a search thread. Perhaps a quick look back to that thread >>> http://www.dynamicdrive.com/forums/showthread.php?t=8567&page=2

As for scrollers, Ive never even used the word here, and I understand how to make the scroller work, Im only interested in the redirect script.

Thank you for not abandoning me:>)

Twey
07-28-2006, 07:01 PM
Argh, you're quite right. I'm sorry, I was becoming confused with a similar thread. Here is the code:
<script type="text/javascript">
window.onload = function() {
window.document.frames['nameOfYourIFrame'].location.href = window.location.search.substr(1);
};
</script>That will work so long as you don't need to pass any GET variables to the page, and will display any page in the iframe that is supplied after the ? on the address bar. I think that's what you want?

jscheuer1
07-29-2006, 05:46 AM
Looks good, Twey. However, testing for the existence of window.location.search would be prudent and, I seem to recall that there were circumstances that would possibly require a test to see if window.location.search contained certain strings before we go off willy nilly loading it into the iframe. At least that was the impression I was starting to get. Also, there seemed to be the matter of .htm getting appended somehow where it wasn't desired, this could be stripped if need be but, would need to be tested and coded to happen only under the appropriate circumstances.

These are the sorts of issues that my seemingly incessant questioning was designed to get at.

Twey
07-29-2006, 05:05 PM
Aha, I see. My apologies.

jscheuer1
07-29-2006, 05:49 PM
Aha, I see. My apologies.

No need to apologise. Your participation, as usual, is appreciated. And seems to be helping to get this thread focused. In fact, considering how diffuse this issue was becoming, I would suggest that MJensen give your code a shot and see what happens. As I have already indicated, I've been having trouble understanding the requirements here. If MJensen tries out your code, it will either satisfy, or point up (at least some of) what needs to be added.

MJensen
07-29-2006, 07:57 PM
Twey, Thank you! yes that is it. However it seems im missing something. The resulting redirect address looked like this:

http://shopmalm.com/index.htm?var1=nccust=malmco&code=3187&page=2

This is missing the following information

domain/dwos-bin/dynamic2.pl? in otherwords var1=domain/dwos-bin/dynamic2.pl?nccust=malmco&code=3187&page=2


So, now how will the script write in the missing address information

Twey
07-29-2006, 08:06 PM
The script doesn't. You do, in the links you create to it.
You also shouldn't have that var1= there. The URL would be:
http://shopmalm.com/index.htm?domain/dwos-bin/dynamic2.pl?nccust=malmco&code=3187&page=2

MJensen
07-31-2006, 07:29 PM
I ve spent hours trying to get this right, to no avail. The complete code for each page would be so nice to have. Im not trying to make linlks, i already have links, i just want ....well the answert to my question which ive restated so many times. Alas, sigh...

jscheuer1
07-31-2006, 10:36 PM
Did we ever get a link to your page? That would probably help clarify matters.

MJensen
08-01-2006, 12:01 AM
1.
[htm.url]

http://shopmalm.com/jewelrywatches.htm


2.
[search.string.url]

http://www.netstores.com/dwos-bin/dynamic2.pl?nccust=malmco&code=72902

The 2nd url is the one i want forced to open inside an iframe of the 1st url

jscheuer1
08-01-2006, 03:58 AM
When I load up your search string link, I get these two errors from the FF javascript console:


Error: body_onload is not defined
Source File: http://www.shopmalm.com/main.htm
Line: 1

and:


Error: body_onload is not defined
Source File: http://www.shopmalm.com/Jewelry%20&%20Watches.htm?var1=http://www.netstores.com/dwos-bin/dynamic2.pl?nccust=malmco&code=72902
Line: 1

When I click to see the code involved on the URLs listed in the error report I see both pages have this:


<body onload="body_onload()"background="" . . .

But, that neither page has a function on it called body_onload(). Also, even if there were, there should be a space after a call like that and having an empty attribute in the body tag like background="" is useless.

On to http://shopmalm.com/jewelrywatches.htm - that page gives these two errors (along with a host of css errors):


Error: body_onload is not defined
Source File: http://www.netstores.com/dwos-bin/catalog.pl?nccust=malmco&page=gallery&skip=0&limit=12&columns=3&Department=Jewelry&Name=Diamond&Description=Earring
Line: 1

and:


Error: refreshFrame is not defined
Source File: http://shopmalm.com/jewelrywatches.htm
Line: 1

For the first error I found the same problem with the body tag as the other two errors above and three body tags!

For the second error I find:


<body onload="refreshFrame();" onload="body_onload()" . . .

Only one onload attribute per body tag allowed (also only one body tag per page). If these functions existed, they could be combined:


<body onload="refreshFrame();body_onload()" . . .

You just cannnot have errors like these and expect other scripts on a page to work. They might but, you cannot take it for granted. Additionally, if these are the functions that you are depending upon for the actions we've been working on in this thread, they must be defined and made available to the pages. If they are just left over from something else, you can safely remove the calls to them.

Take care of those problems and then see what happens.

MJensen
08-02-2006, 11:34 PM
Thank you. I've reviewed and fixed the coding errors as mentioned. Still, i have not been able to complete the script as needed.

jscheuer1
08-03-2006, 07:51 AM
I don't see Twey's script anywhere in evidence. I believe it would go on the top page.

altzens
01-06-2008, 08:28 PM
i just came across this thread looking to force an orphan page back into it's iframe. The script "delineate(text)", etc. works but it occurred to me that if you have that enabled on an iframe page, then anyone can code his own page to force-load into your iframe page just by putting the same code into the head section of his "orphan" page:


<script type="text/javascript">
if (window == top) {
var url='window.location.replace("http://www.domainnameofiframesite.com/index.php?var1='+window.location.href+'")';
eval(url);
}
</script>

and voila, you have an unauthorised third-party page displayed in your iframe.

i looked at the "contPage" code that MJensen used presumably to check myDomain to prevent such an occurrence? but i tried the orphan code on another domain and it still went through.

Is there any way to prevent this?

ps. i'm not a coder just have an avid interest and peripheral knowledge of scripting :)

jscheuer1
01-06-2008, 09:31 PM
That's a very good point. And there were other things about this code that weren't like I would like to see. I think this will take care of the 'URL spoofing' problem and fix some of the other problems I saw -

The top page (some.htm for this example):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function getQval(n) {
if(!arguments[0]||typeof n!='string')
return null;
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}
function refreshFrame() {
var url=getQval('url');
if(url&&url.replace(/www\./,'').indexOf(window.location.host)==window.location.href.replace(/www\./,'').indexOf(window.location.host)&&window.location!=url)
window.frames['maincontentarea'].window.location.replace(url);
}
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", refreshFrame, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", refreshFrame );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
refreshFrame();
};
}
else
window.onload = refreshFrame;
}
</script>
</head>
<body>
<iframe name="maincontentarea" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
</body>
</html>

The potential orphan (filename unimportant):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
if (window == top)
window.location.replace('some.htm?url='+escape(window.location.href));
</script>
</head>
<body>
Hi!
</body>
</html>

Notes: The key here is in comparing the location.hostname object to both the orphaned page and the top page, the position in the location.href of each must be identical to pass. I strip out www. (if found) because that can easily appear, or not, in the location.href object of either page.

altzens
01-07-2008, 10:28 PM
Thanks for your coming back with a solution. i tried it out and the converse happened - the same-domain orphan did not load in the iframe but the illegitimate ones did!

i can figure out the logic in the script somewhat and it makes sense so i don't know where the problem is.

in a primitive attempt, i thought just extracting the domain from "window.location.href" and matching it with the host domain as a condition in refreshFrame() should work. But i can't script so here's a pseudo one with some snippets from the net to show what i mean ...

to extract the domain:

var url = window.location.href;
if(url) {
var domain = url.match( /:\/\/(www\.)?([^\/:]+)/ );
}

and then in refreshFrame() of the original script (i added the green part):

function refreshFrame() {
if(window.location!=url&&domain==hostdomain)
frames['maincontentarea'].window.location.replace(url);
}

Assuming we have the "url" and hostdomain defined, this will obviate the "www" instance (and anything else in the string for that matter) and just check and match the domain names as it were, right?

No matter, i'd prefer your script with all the parameters but i just can't figure out why the converse result. Sure hope you can help because i think it's very practical to have a way to force an orphan page to open in the host iframe provided one can block others.

i appreciate your time on this.

jscheuer1
01-08-2008, 02:33 AM
It works here:

http://home.comcast.net/~jscheuer1/side/orphan.htm

I also tried 'spoofing' with Google:

http://home.comcast.net/~jscheuer1/side/some.htm?url=http%3A//www.google.com/

and, as desired - no dice. Perhaps you misunderstood something about the code.

You can easily see the source code for some.htm. If you want to see it for orphan.htm, just disable javascript before navigating to it.

If you can 'spoof' my example page (some.htm) - other than from home.comcast.net, I'd like to see an example. Who knows, it might be possible. Also, it occurs to me that, if you are dealing with a sub-domain, or just two pages which use a different base URL for any reason (like DNS vs a numbered URL) the script will deny loading into the iframe.

altzens
01-08-2008, 07:30 AM
You are right. i thought about the sub domain bit, and took off "replace(/www\./,'')." from the script and it works fine. But i guess it should be there if the domain is set to resolve with or without the www.

Something else comes to mind ...
Is there any way to tag the iframe id or name to the orphan code so that an orphan page can be directed to a particular iframe if there's more than one in some.htm?

Otherwise they will all open in the "maincontentarea" even if it's not meant to be.

Any thoughts on this is appreciated. Thank you again for your time.

jscheuer1
01-08-2008, 09:06 AM
In a case like that, you could add another parameter on the potential orphan:


<script type="text/javascript">
if (window == top)
window.location.replace('some.htm?url='+escape(window.location.href)+'&fname=side');
</script>

That will set the fname query string value as side. Then use this on the target page with the iframes on it:


<script type="text/javascript">
;(function(){
var getQval = function (n) {
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}, refreshFrame = function() {
var fname=getQval('fname')? getQval('fname') : 'maincontentarea';
window.frames[fname].window.location.replace(url);
}, url=getQval('url'),
idx=function(s){return s.replace(/www\./,'').indexOf(window.location.hostname.replace(/www\./,''));};
if(url&&idx(url)==idx(window.location.href)&&window.location!=url){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", refreshFrame, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", refreshFrame );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
refreshFrame();
};
}
else
window.onload = refreshFrame;
}}})();
</script>

It will load into an iframe with the name of side:


<iframe name="side" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>

Note: I figured out the trouble with the hostname test and www., fixed (highlighted green in the above). The issue was that if www. is stripped from either or both of the URL(s), it must also be stripped from the location.hostname object as well for a proper comparison.

altzens
01-08-2008, 04:06 PM
it all works fine now :)

Thanks a bundle for taking the time to look into it.

Have a nice day and best wishes for the year ahead!

jscheuer1
01-08-2008, 09:53 PM
Oh, you are welcome. Sometimes they say that there are no such things as stupid questions, just stupid answers. However, in this particular case, yours was a very smart question.

I was playing around with the code a bit more and realized it should work for a frameset too. It did, but with one important change which doesn't adversely affect its performance with iframe(s). I also added a function (green) to the idx function simply to allow me to compress the code (byte-wise) a little more and came up with this:


<script type="text/javascript">
;(function(){
var getQval = function (n) {
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}, refreshFrame = function() {
var fname=getQval('fname')? getQval('fname') : 'maincontentarea';
window.frames[fname].location.replace(url);
}, url=getQval('url'),
idx=function(s){var r=function(i){return i.replace(/www\./,'');};
return r(s).indexOf(r(window.location.hostname));};
if(url&&idx(url)==idx(window.location.href)&&window.location.href!=url){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", refreshFrame, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", refreshFrame );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
refreshFrame();
};}
else window.onload = refreshFrame;}}})();
</script>

The important change was from:


window.frames[fname].window.location.replace(url);

to:


window.frames[fname].location.replace(url);

The more verbose method is redundant and was causing a security violation in IE with a frameset. Either way appears fine with iframe(s).

altzens
01-09-2008, 08:00 AM
"those who can, do; those who cannot, teach" ... some can do both, others should start by asking! I'm glad i did. :)

I had noticed the "idx" truncated code from the souce of some.htm earlier - made sense but i do appreciate your initial verbose version so i could better follow the logic which helped. This last script works fine too and i think it could be a base to add a few more functions or parameters. Thinking aloud ...

You know how it is with Google not indexing the contents of iframes ... if one could add content (meta description or page summary) to the iframe section or <no frameset> body each time a page (orphan or otherwise from links within the parent) loads in the iframe, those gbots may still get to it! Just wondering if it could be invoked when 'window.frames[fname]... does it's thing or maybe this requires php. I guess the content must be in an array and drawn from some prefilled flatfile database so there could be another getQval() for it ...

I should quit while i'm ahead before the question gets rather silly! It occurred to me only because indexing is rather important for now and it would be a shame to forego iframes and with it some design aesthetics just because the page won't do well in search engines ... I believe there can be an optimal solution.

Anyways, i think i've exceeded the realm of this topic and with it your time.

Many thanks.

jscheuer1
01-09-2008, 04:10 PM
I think (though I am not certain) that if you want Google to index your 'orphans', you need only link to them from a page that is indexed. This can be done while targeting the iframe.

If that works, and I think it should - especially if the targeting is done only via javascript, links to 'orphans' from 'orphans' that are linked to in this manner (targeted to the iframe from an indexed page) should also get indexed. My reasoning is that, to the spiders sent out to index these things, the javascript targeting should be ignored, while the HTML links should be followed.

altzens
01-09-2008, 08:33 PM
You are right about the html links (targetting the iframe) being indexed. So the trick then is to make sure that top level orphans get iframe-targetted from an indexed page so that all other orphans linked within top level ones also get indexed.

Alas, the ones that are on their own will not get indexed since the only way they will be linked to their iframe-page is by javascript. Unless you add another parameter to it, say " +'&flink=nameoforphanpage.htm' " or something to that effect and have that flink value load within the iframe tags where normally this would go:

... This page does not support iframes. Click <a href="">here</a> to view the page in another window.</iframe>

and have the href reference "+flink+" or something. In this way, it will be a html link and presumably will get spidered when the gbot visits.

Maybe there's a simpler way ;)

jscheuer1
01-10-2008, 03:37 AM
Define 'on their own'. I'm confused. If the only way these pages ever get en-framed is via the javascript we've been discussing in this thread being on them, how will anyone ever find them in the first place, let alone a search engine spider?

altzens
01-10-2008, 06:40 AM
Sorry, i was not clear. I meant those orphan pages that are not html-linked to within its iframe-page but merely load (via javascript) into an iframe because it's forced to.

On hindsight, this distinction does not serve any purpose because now that you mention it, there is no way any orphan pages will be spidered if they appear through this en-frame process because the targetting will always be via javascript. Even a html-link on the iframe page targetting the iframe merely loads it into the iframe which as reported is not indexed.

So i guess it's back to square one with the non-indexing of iframes unless there's a way to document.write a meta-description or page summary between the iframe tags so at least some keywords of that orphan page can be spidered. Looks like i'll need to do more reading on this :)

jscheuer1
01-10-2008, 12:02 PM
I'm still not 'getting it'. The top page will be indexed. If a page is loaded into an iframe named 'bob' on the top page:


<a href="potential_orphan.htm" target="bob">Neat Info</a>

it will be indexed. Any page linked to potential_orphan.htm will be indexed, and any page linked to those pages will be indexed.

Now, once indexed, they may be arrived at outside of the iframe, but our code will force them back inside it. This in itself will not 'un-index' them.

If there were no link to some pages from anywhere, they wouldn't be indexed, but they wouldn't be found by anyone either, so would never appear in or out of the iframe.

altzens
01-10-2008, 06:13 PM
I see why i'm not clear, my apologies. When i refer to "indexing" i'm refering to the process where the gbot "compiles a massive index of all the words it sees and their location on each page" as opposed to the gbot "crawling" a page where all it does is (here's were the confusion lies) index it for links.

You are right about the latter (i.e. "crawling") - the html-links do get indexed. But when the gbot does the former (indexing content for keyword density, etc. to rank), the content of the orphan page which loads into the iframe will not be "indexed" as the iframe tag is a blindspot as far as the gbot is concerned. If the iframe/orphan page holds the bulk of the content, some.htm will rank poorly in search results, if at all, as the gbot has picked up nothing except for text-links to ".htm" files but no content.

Google makes this differentiation in crawling, indexing and serving results:
http://www.google.com/support/webmasters/bin/answer.py?answer=70897&topic=8460

If i got this right, the gbot will skip the iframed page and only record text-links in the parent and if present, any text-content within the iframe tags which is usually there for browsers that do not support iframes.

And if that's the case, it would be helpful if one could write content between the iframe tags whenever an orphan page loads, at least that would be spidered by gbot for that page even if it just keywords or a short description of the orphan page.

Does this make any sense? Anyway i tried scripting a parameter "ftext=blah blah" to the orphan page and doing a getQval() to extract it and a getElementByid.innerHTML to write it to a <p id=text></p> within the iframe tags but needless to say, my attempt at scripting didn't work ;)

FYI, i noticed the browser debugger show an alert in the status bar when some.htm is loaded but goes off if a text-link is clicked to load a page in the iframe. The alert says "object expected" - no alerts if the script is not used.

I hope i've not made it more confusing.

jscheuer1
01-10-2008, 06:21 PM
As long as the 'orphan', which isn't really an orphan if it is linked to somehow along the chain of links we've been discussing, gets indexed and will bring on the top page if navigated to by itself, what's the difference? The top page may rank poorly, but will still be displayed when a user clicks on the link to the 'orphan' which presumably ranks well.

altzens
01-10-2008, 08:17 PM
Only unforced (standalone) orphan pages will be spidered for content since its just another page on the site as far as the bot is concerned. In that case, it will rank as it should.

But orphan pages that are forced to load in iframes will never get spidered (content-wise) due to the blindspot; consequently it's content will not get indexed. This leaves a site with a poorly ranked parent page and unranked orphans. It will not matter if there are html-links to it from any indexable page since the bot will follow it back to its parent and skip the blindspotted iframe where it loads.

Apart from writing content between the iframe tags which i will continue to experiment, i can't think of any other solution as yet short of having the standalone page self-destruct (close its window after a 5 sec delay) leaving a pop-under parent with orphan duly iframed!

Whether its standalone orphans or blindspotted ones, at least now the parent is spoof proof. :)

jscheuer1
01-10-2008, 08:25 PM
Put a link there:


<iframe src="not_really_an_orphan.htm"><a
href="not_really_an_orphan.htm">Some Neat Page</a></iframe>

Then all of the normal links on and on pages linked to:

"not_really_an_orphan.htm"

that will end up in most cases, one way or the other, loading into the iframe, should get fully indexed.

But I think you are making too much of this 'blind spot' concept. As long as a page has a link on the top page:


<a href="an.htm" onclick="window.frames['iframe_name'].location=this.href;return false;">An HTML Page</a>

The pages linked to it and to those pages should get indexed. Perhaps even just a link like so would suffice:


<a href="an.htm" target="iframe_name">An HTML Page</a>

which if it would, would be preferable. One of the three strategies should work.

altzens
01-11-2008, 04:32 AM
The text-link i have been alluding to (the one you have in green) is not dynamic. By that i mean it will not change when an orphan loads (when the iframe src is targetted) unless some script (e.g. the parameter ftext or such i was trying to do) document.writes it there each time the src changes. That's the only way that part can be spidered and of relevance to the orphan that loads. Also, it need not be restricted to a text-link to Some Neat Page but may include an image or short description of the page.

So far this seems the only way to get any content of the orphan indexed. Again, for clarity, in particular reference to rank value of a page through "valuable content", indexing of content and indexing (crawling for links) of links must be differentiated.

My point is that a html-link to "an.htm" serves no purpose other than to have the bot index that such a link exists in the site. The bot will not be able to spider the content of the orphan page due to it unloading in an iframe which is blindspotted, for want of a better term.

Here's my feeble attempt at writing the iframe-content (where the text-link to Some Neat Page currently is) by introducing a parameter to the orphan script:

if (window == top&&
location.search.substring(1) != 'nf')
window.location.replace('http://www.somedomain.com/some.htm?url='+escape(window.location.href)+'&fname=main&ftext=someiframecontent');

and in the parent script i added:

var ftext=getQval('ftext')? getQval('ftext') : 'someothercontent';
document.getElementById('main_text').innerHTML = ftext;

below this:

var fname=getQval('fname')? getQval('fname') : 'main';
window.frames[fname].location.replace(url);

and in the iframe body, i placed the ID tag which in your example would be:

<iframe src="not_really_an_orphan.htm"><p id='main_text'>someothercontent</p><a
href="not_really_an_orphan.htm">Some Neat Page</a></iframe>

It didn't work but you get what i'm trying to do. ;)

jscheuer1
01-11-2008, 05:51 AM
I don't see this 'blind spot'. The link is a legitimate link, so will be followed by the spider to the page, which will then be indexed, any links on that page will also be followed and their pages indexed, and so on. It doesn't matter that this isn't the path that actual users of the site will take to see the content, it is the path the spider will take.

altzens
01-11-2008, 07:45 AM
"it is the path the spider will take" - if you are sure about that, i stand corrected.

In my opinion, the uncertainty lies in 'what page?' when you say "the link is a legitimate link, so will be followed by the spider to the page". My view is that as far as forced orphan pages are concerned (leaving the standalone ones out), "the page" is the poorly ranked parent page with a non-indexable iframe within which the forced ophan opens and not the orphan page itself which as we know has been scripted to appear in its iframe. So no matter how many loops the bot does in following the orphan page link, it will always end up with its parent (with non-indexable iframe) and so it doesn't matter if the orphan has links or any content for that matter, the bot will not get to it.

But if you think the bot can read content in an iframe which is where we differ, then there's no basis for my concern. In fact i hope i'm wrong :)

... then again, if i'm right, birky will get paid for his work! ;)
http://www.dynamicdrive.com/forums/showthread.php?t=27073

Still it's nice to exchange ideas and i do appreciate your time on this.

I will start looking at php includes as an alternative to iframes and see how that pans out :)

jscheuer1
01-11-2008, 08:06 AM
The spider will not read the content in the iframe. It will read the content on the page linked to inside the iframe tag. The end result will be about the same.

However, it is true that the top page, if poorly conceived, will not rank well. It should at the very least have a good title and heading(s), and perhaps a paragraph as well that all at least lay out the general thrust of the site. Once again though, you could put all manner of things (must be hard coded) in that iframe tag to boost its ranking - almost no one, except bots will ever see it. I see no real need to do so though, because the page that is in it, which presumably will rank well, when navigated to, will invoke the top page.

altzens
01-11-2008, 09:03 AM
Generally, the bot will have read the content of a page linked inside an iframe tag if it is html-linked from any indexable page or even if there's a text-link to it between the iframe tags as alluded. It will have read the page's content from the page url itself not while spidering the parent and certainly not through the src link in the iframe tag.

The concern is that in the case of a forced ophan page, can the bot read its content from the forced ophan's own url since the page is forced to open in its parent? The bot ends up reading the parent instead without any access to the actual content of the forced orphan page. But this could be a misconception on my part.

It might be that the bot will spider the content of a forced orphan page as long as it's a html page despite it having a script that will force it to open in an iframe. That's altogether possible - i don't know that for a fact - but if that's indeed the case, this is a very compelling argument for iframes (particularly so in the context of forced orphans) now that the spoofing issue is taken care of.

Might very well be so since presumably a bot does not need to bring up a page (only humans will) to "view" it and in that sense, will have access to its content bytes regardless of any script making it open elsewhere! If so, the forced orphan page will have a ranking chance. Fair enough.

Thank you for your patience and willingness to stay the course! :)

jscheuer1
01-11-2008, 09:16 AM
Bots ignore scripts. So, if the page is linked to (it must in some fashion be 'linked to' for anyone ever to get to it the first time), it will be indexed. If the only way anyone ever gets to it is via javascript, a link to it must be created somewhere. Generally, a javascript only link can be made into a regular link with a javascript assist, or you can add all links that would otherwise not be on any of the other pages to the area inside the iframe tag. This is good for accessibility anyway, as is a division that contains links to all pages not otherwise linked to. Javascript can hide this division from those with javascript enabled.

But, if you have a link in the iframe tag to its initial src page, and there are links from it to all other pages that will go in the iframe and/or from the sub-pages themselves to each other, if there is a chain of links, that is all that is required for the bot.

altzens
01-11-2008, 09:46 AM
Good to know! Thanks :)

On a related matter, i came across this:


if (self.location == top.location &&
location.search.substring(1) != 'nf')
top.location.href = 'mypage.html?' + escape(self.location);

If a page containing this code is accessed from outside of the iframe then provided that the browser supports Javascript this code will cause the page with the iframe to be loaded in its place and the current page address will be passed to be loaded into the iframe.

If the browser doesn't support Javascript then the individual page will still display outside of the iframe. There is nothing we can do about that. The noscript section of the iframe page ensures that the iframe still displays correctly if Javascript is not available and the content of the iframes handle the situation where the browser doesn't support iframes.

Since we are loading the page into a separate browser window when the page doesn't support iframes we don't want that window trying to reload the page back into an iframe again. To stop this from happening we pass it a query string of 'nf' to tell it that it is allowed to be displayed without the iframe wrapper in this instance.

Is this useful or necessary in our case of forced orphans?

jscheuer1
01-11-2008, 03:59 PM
That appears to be only a partial explanation of a rather lengthily thought out approach to something very similar to what we've set up. Without seeing the full explanation and recommendations it would be hard to say for sure if it is really a good idea.

It looks as though it would only be of use as regards links on your site to your site and off site links to your site where you have control over what the href or URL value will be. And only if there actually are pages that under no circumstances should be displayed without being inside your iframe. And it will probably fail if those pages are indexed by a search engine. Indexing by the search engines can be prevented for pages you choose to do that for, at least for the most part, but you cannot control how your page might be bookmarked, navigated or linked to by humans.

The part:


self.location == top.location && location.search.substring(1) != 'nf'

is functionally the same as:


window == top && location.search.substring(1) != 'nf'

The added:


&& location.search.substring(1) != 'nf'

bit looks as though it depends upon your being able to make certain that every time that this page is reached it is with a URL that ends in (and has no other query data in its URL):

?=nf

which is syntactically incorrect for a query string and for a URL, nor is it likely that you would have total control over that happening every time the page is reached.

I would like to reserve final judgement on this though, until I saw the whole code and could read its concept's full explanation.

altzens
01-11-2008, 05:47 PM
Can't find the page again - if i remember correctly, the author came up with a javascript to be placed where the iframe should go and did a document.writeIn for the iframe tag attaching this ?nf bit to the orphan page url (probably from the location.search string) to make it work as he commented.

But i see your point. Without total control over the url, it's pointless.

Thanks for the input.

Btw, i found out why there was a browser debug alert in the status bar when the parent page loads on its own - what happened was i still had the refreshFrame() onload in the <body> tag from the previous delineate(text) script. With window.onload already in the parent script, that was redundant and it probably triggered what the "window.addEventListener" operator was suppose to prevent - just my guess. But no more alerts when i removed it from the <body> tag :)

still lots to learn ...

jscheuer1
01-11-2008, 08:28 PM
With such a detailed quote, I'm surprised you couldn't find the reference again. I searched on (quote marks included):

"If a page containing this code is accessed from outside of the iframe"

I found one hit:

http://javascript.about.com/library/bliframe.htm

I'll be having a look at it at my leisure. But out of curiosity, though I am 99% sure it is what you were referring to, is it?

altzens
01-11-2008, 09:41 PM
Yes, that's the one! I copy/paste lots of information into sticky notes that i think may be of help later - I think i was looking for parameters at that time to put in the orphan or something. Anyway, i couldn't make sense of the ?nf and didn't pursue it further.

So what do you think of it?

jscheuer1
01-12-2008, 02:59 AM
I've read the article now. I think it makes a good point, but it is a fine point these days. Folks who, these days, refuse iframe should also be savvy enough to also disable javascript, but I think for future compatibility, given that iframe is in the process of being deprecated, something should be done, but perhaps (due to other considerations) not precisely in the way that the article recommends. I will have to get back to you after I have given this more thought.

A little back story would probably be good. When that article was written there appears to have been no focus on SEO (Search Engine Optimization) or things regarding SEO were different than today, and it was probably also at a time when browsers that simply couldn't support iframe were much more common than they are today.

However, this brings to light an issue that I assumed you were already aware of. The iframe tag is in the process of being deprecated. It will probably continue to be supported for quite some time to come, perhaps indefinitely, but one cannot be certain of this. The same is true for framesets. So, you may want to reconsider your use of iframe and/or frame, and go with something else like Ajax imported pages or just (shudder) regular pages.

Twey
01-12-2008, 02:32 PM
Folks who, these days, refuse iframe should also be savvy enough to also disable javascriptConsider eLinks: Javascript support, but no <iframe> support.
The iframe tag is in the process of being deprecated.Pedantry perhaps, but bear in mind the difference between "tag" and "element." A tag is the textual markup that describes an element in the DOM.

jscheuer1
01-12-2008, 03:44 PM
Consider eLinks: Javascript support, but no <iframe> support.Pedantry perhaps, but bear in mind the difference between "tag" and "element." A tag is the textual markup that describes an element in the DOM.

I was wondering if there were such a browser and was happy to see you provide one but (from the top of their download page):


Unstable GIT snapshot: elinks-0.12 tar.bz2 (sum) tar.gz (sum)
Stable GIT snapshot: elinks-0.11 tar.bz2 (sum) tar.gz (sum)
Current stable (codename Elated): elinks-0.11.3 tar.bz2 (sum) (asc) tar.gz (sum) (asc)
Other versions are no longer maintained; bug fixes will not be backported to them.

I'm sorry, this is a Super Geeks Only browser, so technically doesn't count. The geeks who use this thing will deal as easily with iframes having this sort of javascript associated with them as they will with tar.bz2, etc.

I would like to find a browser like that which is at least as accessible as iframes are. :) I really would, to find out the shortest effective javascript test for iframe support.

I'm afraid though, that iframe being as non-standard as it is, will mean that each browser that excludes them will probably do so in a non-standard sort of way.

I have come up with an approach for dealing with them all though, it's just a bit more involved than I would like. After I've a bit of time to see if I can cut down on the code and consider some ideas for making it even more effective, I will post it.

Twey
01-12-2008, 04:00 PM
The geeks who use this thing will deal as easily with iframes having this sort of javascript associated with them as they will with tar.bz2, etc.It's a GNU/Linux browser, where .tar.bz2 support is in every distro by default and the user probably wouldn't touch the tarball anyway :) It would probably be more of a case of yum install elinks or ticking a box on a GUI window.
I'm afraid though, that iframe being as non-standard as it is, will mean that each browser that excludes them will probably do so in a non-standard sort of way.A browser that doesn't support an element will ignore that element's tag, so the element will not appear in the DOM tree. It will also throw an exception when you try to createElement() the element.

jscheuer1
01-12-2008, 04:18 PM
Yum? Definitely Super Geeky.

Yes, browsers that ignore iframes will do so in the standard way, or should. However, there are various hacks and/or mods I seem to remember hearing about that kill iframes or whatever, in connection with avoiding ads mostly. I'm not sure how all of the various approaches to this would work with this script. I also seem to remember that, at least the best of them will accept iframes whose source is from the same domain.

Twey
01-12-2008, 04:41 PM
If the user mods his/her browser and it's done poorly, it's not the developer's duty to try to fix it.
Yum? Definitely Super Geeky.How so?

jscheuer1
01-12-2008, 04:46 PM
I'm fairly knowledgeable and have only occasionally ever heard mention of it, never used it, wouldn't know the first thing about using it, at least not that I am aware of.

It may be fairly common on 'nix, perhaps even Mac, but I doubt it is really intended for the casual user. Don't hold me to that though, the truth is I really know little or nothing about it. I doubt that (relatively speaking) many folks do.

Twey
01-12-2008, 05:45 PM
It was just an example of a package manager command. It's quite rare to install software manually on Linux: usually a package manager is used to do it automatically. Equivalent commands could be:
apt-get install elinks # Debian/Ubuntu
emerge elinks # Gentoo
pacman -S elinks # ArchAgain, though, for all of these graphical interfaces are provided where the user simply ticks a box and hits "apply."

jscheuer1
01-12-2008, 06:45 PM
I used to play pacman, but that's entirely different. You are more or less agreeing with me, and I think it's wonderful what one can do with Linux and other 'nix type OS's. It's not very widely done, I mean the subset of 'nix users is small enough, and here we are talking about a subset of those folks who compile and run eLinks as their primary browser. Now, if you do happen to be using eLinks, how difficult is it to temporarily disable javascript? I would hope it would be easier than installing eLinks, at least as easy as on IE, hopefully easier. But I don't want to assume.

None of this changes the fact that the script code under discussion in this thread would be more comprehensive with allowance made for browsers like eLinks, and for others with iframe disabled, javascript enabled. And, I've never maintained that code for that shouldn't be added. I'm just not happy with how it was done in the article cited in this thread that was the basis for bring up this aspect of the code. I don't like its reliance upon the target attribute or the <noscript> tag, or its use of a non-standard query syntax which appears to assume no other query data for examples. And I would want to integrate the added code more directly into the existing code. I pretty much have that wrapped up, I'm just trying to decide on two methods of dealing with the content for non-javascript enabled browsers and waiting on further inspiration on possibly making the code more universal. I'm not always happy assuming and relying upon browsers always reacting in a standard manner.

I would love to be able to test for support of iframe as simply as:


if(window.frames)

My initial reaction to that is, 'close, but no cigar', though. What do you think?

More to come . . .

Twey
01-12-2008, 07:11 PM
I would hope it would be easier than installing eLinksEasier than ticking a checkbox? What's that, telepathy? :) It's enabled/disabled via Setup->Options manager->ECMAScript->Enable.
I would love to be able to test for support of iframe as simply as:No -- eLinks supports frames, just not <iframe>s. You'd have to do:
var iframeSupport = true;
try {
document.createElement("iframe");
} catch(e) {
iframeSupport = false;
}

jscheuer1
01-13-2008, 07:38 PM
I'm relieved that eLinks users can so easily disable javascript. That's about how I imagined it would be, I just didn't know.


You'd have to do:
var iframeSupport = true;
try {
document.createElement("iframe");
} catch(e) {
iframeSupport = false;
}

That won't work in Opera with iframes disabled, perhaps not others, perhaps not any. In Opera with iframes disabled, you can create, destroy, read/edit their properties, etc. They just don't have visibility.

Anyways, my script is ready for beta:


/* frameIt for iframes script 2008 John Davenport Scheuer
* as first seen in http://www.dynamicdrive.com/forums
* username: jscheuer1 This notice must remain for legal use. */

getRun.dFault='maincontentarea' //set name of default iframe

/*
Usage - Place this in the head of your page with iframe(s):
<script src="frameIt.js" class="top" type="text/javascript"></script>

Place this inside the iframe tag, preceded by an optional noframes and no javascript link tag:
<script src="frameIt.js" class="frame" type="text/javascript">

Place this in the head of the external page which should be en-iframed:
<script src="frameIt.js" class="IFRAME_NAME" type="text/javascript"></script>
Use the name of the target iframe as the class or, use no class attribute
if the target iframe is the default iframe
*/

function getRun(){
if(!document.createElement)
return null;
var s=document.getElementsByTagName('script');
return s[s.length-1].className? s[s.length-1].className : getRun.dFault;
}

getRun.getQval=function(n) {
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}

if(getRun()=='top'){
;(function(){
var refreshFrame = function() {
var fname=getRun.getQval('fname')? getRun.getQval('fname') : getRun.dFault;
window.frames[fname].location.replace(url);
}, url=getRun.getQval('url'),
idx=function(s){var r=function(i){return i.replace(/www\./,'');};
return r(s).indexOf(r(window.location.hostname));};
if(url&&idx(url)==idx(window.location.href)&&window.location.href!=url){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", refreshFrame, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", refreshFrame );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
refreshFrame();
};}
else window.onload = refreshFrame;}}})();
}

else if(getRun()=='frame'){
;(function(){
var l=document.links[document.links.length-1], re=new RegExp('^.*\/([^\/]+)')
f=document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length-1];
if(l.href.replace(re,'$1')==f.src.replace(re,'$1'))
l.parentNode.removeChild(l);
var url=getRun.getQval('fname')==f.name?getRun.getQval('url'):f.src;
document.write('<a href="'+url+'?nf=1">No iFrames Link<\/a>');})();
}

else if(getRun()&&!getRun.getQval('nf')&&window.location.replace&&window.frames&&window == top)
window.location.replace('some.htm?url='+escape(window.location.href)+(getRun()? '&fname='+getRun() : ''));

Example top page:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="frameIt.js" class="top" type="text/javascript"></script>
</head>
<body>
<iframe name="maincontentarea" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1">
<a href="about:blank">Blank</a>
<script src="frameIt.js" class="frame" type="text/javascript"></script>
</iframe><br>
<iframe name="side" src="potential_orphan.htm" width="300" height="300" scrolling="auto" frameborder="1">
<a href="potential_orphan.htm">P Orph</a>
<script src="frameIt.js" class="frame" type="text/javascript"></script>
</iframe>
</body>
</html>

Example external page:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="frameIt.js" class="side" type="text/javascript"></script>
</head>
<body>
Hi!
</body>
</html>

Twey
01-13-2008, 07:42 PM
In Opera with iframes disabled, you can create, destroy, read/edit their properties, etc. They just don't have visibility.Truly? That's quite a broken implementation in my opinion.

jscheuer1
01-13-2008, 08:16 PM
Truly? That's quite a broken implementation in my opinion.

Truly. I thought so at first too, and it may well be, but remember iframe is transitional and less only - no more, no less. So, if your browser is in compliance, it may choose not to render the external content of the tag, but it had better recognise it as a valid tag in that DOCTYPE, otherwise the browser is broken. At least so I would think.

And, though I know it isn't standard even for transitional, IE 7, FF 2.0.0.11, Safari 3 Win, and Opera 9.24 all alert 2 for this page:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div id='huh'></div>
<barf>Bleh</barf>
<script type="text/javascript">
var b=document.createElement('barf');
document.getElementById('huh').appendChild(b);
alert(document.getElementsByTagName('barf').length);
</script>
</body>
</html>

Go figure?! Try it out in eLinks and Konq for me if you will.

jscheuer1
01-14-2008, 04:55 AM
OK, the beta of this script is coming along, it is now back to being for iframe or frames, but as I have no truly frames incapable browser to readily test on, I am going to assume that simply testing for window.frames will exclude those from endless loops, as long as the ?nf=1 query is attached to noframes content href's for browsers that may come down somewhere in the middle. This is documented in the new version which also allows for an optional top page to be passed along to the script:


/* frameIt for frames and iframes script 2008 John Davenport Scheuer
* as first seen in http://www.dynamicdrive.com/forums
* username: jscheuer1 This notice must remain for legal use. */

getRun.dFault='maincontentarea' //set name of default frame/iframe
getRun.topPage='some.htm' //set default location of frames/iframes page

/*
Usage - Place this in the head of your page with frames/iframe(s):
<script src="frameIt.js" class="top" type="text/javascript"></script>

IFRAME ONLY
Place this inside the iframe tag, preceded by an optional no iframes and no javascript link tag:
<script src="frameIt.js" class="iframe" type="text/javascript">

FRAMESET ONLY
Place links like this inside the body and noframes tag so that javascript and non-javascript users
can access the pages outside the frameset:
<a href="PAGE_NAME?nf=1">Link Text or Image</a>

Place this in the head of the external page which should be en-framed:
<script src="frameIt.js" class="[I]FRAME_NAME::OPTIONAL_TOP_PAGE" type="text/javascript"></script>
Use the name of the target frame/iframe as the class or, use no class attribute if the target frame/iframe
is the default frame/iframe, optional top page location may be supplied here as well, use :: separator.
*/

function getRun(){
if(!document.createElement)
return null;
var s=document.getElementsByTagName('script');
return s[s.length-1].className? s[s.length-1].className : getRun.dFault;
}

getRun.getQval=function(n) {
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}

if(getRun()=='top'){
;(function(){
var refreshFrame = function() {
var fname=getRun.getQval('fname')? getRun.getQval('fname').split('::')[0] : getRun.dFault;
window.frames[fname].location.replace(url);
}, url=getRun.getQval('url'),
idx=function(s){var r=function(i){return i.replace(/www\./,'');};
return r(s).indexOf(r(window.location.hostname));};
if(url&&idx(url)==idx(window.location.href)&&window.location.href!=url){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", refreshFrame, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", refreshFrame );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
refreshFrame();
};}
else window.onload = refreshFrame;}}})();
}

else if(getRun()=='iframe'){
;(function(){
var l=document.links[document.links.length-1], re=new RegExp('^.*\/([^\/]+)')
f=document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length-1];
if(l.href.replace(re,'$1')==f.src.replace(re,'$1'))
l.parentNode.removeChild(l);
var url=getRun.getQval('fname')==f.name?getRun.getQval('url'):f.src;
document.write('<a href="'+url+'?nf=1">No iFrames Link<\/a>');})();
}

else if(getRun()&&!getRun.getQval('nf')&&window.location.replace&&window.frames&&window == top){
var dat=getRun().split('::'), fname=dat&&dat[0]? dat[0] : null;
getRun.topPage=dat&&dat[1]? dat[1] : getRun.topPage;
window.location.replace(getRun.topPage+'?url='+escape(window.location.href)+(fname? '&fname='+getRun() : ''));
}

Example pages are as before, except that the class="iframe" replaces the class="frame" from before. This is to prevent undue confusion about where it can be used, ex:


<iframe name="side" src="potential_orphan.htm" width="300" height="300" scrolling="auto" frameborder="1">
<a href="potential_orphan.htm">P Orph</a>
<script src="frameIt.js" class="iframe" type="text/javascript"></script>
</iframe>

And we now can optionally add a top page to the class on the external page using :: as a separator:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="frameIt.js" class="side::some2.htm" type="text/javascript"></script>
</head>
<body>
Hi!
</body>
</html>

Note: For some strange reason, the validator doesn't like class as an attribute for the script tag. However, it is a part of the specification, see:

http://www.w3.org/TR/html401/index/attributes.html

I appear to have spoken too soon, the W3C contradicts its own published information in the actual DTD for the DOCTYPE, class appears to not be valid for the script tag.

jscheuer1
01-14-2008, 09:34 AM
OK, we can do it like so and validate:


/* frameIt for frames and iframes script 2008 John Davenport Scheuer
* as first seen in http://www.dynamicdrive.com/forums
* username: jscheuer1 This notice must remain for legal use. */

getRun.dFault='maincontentarea' //set name of default frame/iframe
getRun.topPage='some.htm' //set default location of frames/iframes page

/*
Usage - Place this in the head of your page with frames/iframe(s):
<script src="frameIt.js?load=top" type="text/javascript"></script>

IFRAME ONLY
Place this inside the iframe tag, preceded by an optional no iframes and no javascript link tag:
<script src="frameIt.js?load=iframe" type="text/javascript">

FRAMESET ONLY
Place links like this inside the body and noframes tag so that javascript and non-javascript users
can access the pages outside the frameset:
<a href="PAGE_NAME?nf=1">Link Text or Image</a>

Place this in the head of the external page which should be en-framed:
<script src="frameIt.js?load=[I]FRAME_NAME::OPTIONAL_TOP_PAGE" type="text/javascript"></script>
Use the name of the target frame/iframe as the load query or, use no query if the target frame/iframe
is the default frame/iframe, optional top page location may be supplied here as well, use :: separator.
*/

function getRun(){
if(!document.createElement)
return null;
var s=document.getElementsByTagName('script'), r=getRun.getQval('load', s[s.length-1].src);
return r? r: getRun.dFault;
}

getRun.getQval=function(n, s) {
var r=new RegExp('[?&;]'+n+'=([^&;#]*)'), m=s? s : location.search;
return (m=r.exec(m))? unescape(m[1]) : null;
}

if(getRun()=='top'){
;(function(){
var refreshFrame = function() {
var fname=getRun.getQval('fname')? getRun.getQval('fname') : getRun.dFault;
window.frames[fname].location.replace(url);
}, url=getRun.getQval('url'),
idx=function(s){var r=function(i){return i.replace(/www\./,'');};
return r(s).indexOf(r(window.location.hostname));};
if(url&&idx(url)==idx(window.location.href)&&window.location.href!=url){
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", refreshFrame, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", refreshFrame );
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
refreshFrame();
};}
else window.onload = refreshFrame;}}})();
}

else if(getRun()=='iframe'){
;(function(){
var l=document.links[document.links.length-1], re=new RegExp('^.*\/([^\/]+)')
f=document.getElementsByTagName('iframe')[document.getElementsByTagName('iframe').length-1];
if(l.href.replace(re,'$1')==f.src.replace(re,'$1'))
l.parentNode.removeChild(l);
var url=getRun.getQval('fname')==f.name?getRun.getQval('url'):f.src;
document.write('<a href="'+url+'?nf=1">No iFrames Link<\/a>');})();
}

else if(getRun()&&!getRun.getQval('nf')&&window.location.replace&&window.frames&&window == top){
var dat=getRun().split('::'), fname=dat&&dat[0]? dat[0] : null;
getRun.topPage=dat&&dat[1]? dat[1] : getRun.topPage;
window.location.replace(getRun.topPage+'?url='+escape(window.location.href)+(fname? '&fname='+fname : ''));
}

Example top page:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="frameIt.js?load=top" type="text/javascript"></script>
</head>
<body>
<iframe name="maincontentarea" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1">
<a href="about:blank">P Orph</a>
<script src="frameIt.js?load=iframe" type="text/javascript"></script>
</iframe><br>
<iframe name="side" src="potential_orphan.htm" width="300" height="300" scrolling="auto" frameborder="1">
<a href="potential_orphan.htm">P Orph</a>
<script src="frameIt.js?load=iframe" type="text/javascript"></script>
</iframe>
</body>
</html>

Example external page:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="frameIt.js?load=side::some.htm" type="text/javascript"></script>
</head>
<body>
Hi!
</body>
</html>

molendijk
01-14-2008, 11:30 AM
Hello Altzens,
But that code causes flicker on page transition if you go from one orphaned page to another via links. That's why I proposed this (http://www.dynamicdrive.com/forums/showthread.php?t=27269) in another thread.

By the way: once iframes get really deprecated, you can replace them with <object ...></object>, see here (http://intranation.com/test-cases/object-vs-iframe/).

John's solution seems OK. I'm going to test it.

Arie Molendijk.

altzens
01-14-2008, 06:27 PM
Hi Arie,


But that code causes flicker ...
I've not tried John's getRun. code but the one before this works fine. If you are refering to basic target iframe links from a top/parent page, I didn't notice any flicker but maybe that's because my eyes frame-speed is browser-compatible ;)

I took a look* at your orphaned pages script but not sure if it prevents spoofing which was my original post when looking at another orphan page script i stumbled on elsewhere. Next, i came across some other parameter (?nf) that tackled the issue of what i would call an estranged page - an orphan page (forced back in) but bumped out in a no js/iframes scenario. I wanted to know what it did and i guess the getRun. script makes it accessible outside the frameset which may be helpful.

I will go for a what-works-for-now-and-in-the-near-future strategy to build a site - change is a constant with the web and i'm quite confident that like water, a web interface will find it's own level with whatever's available at the time. Even with this iframes effort so far, i just tried Ajax and it works fine for a tabbed interface but perhaps opens a new can of worms - which is okay, adds to the knowledge base. I think an iframe/Ajax combo should do to draw from the strengths of each until some other solution comes along. Come to think of it, it's probably time for a new look at how the web serves content.

*non-coder viewpoint

molendijk
01-14-2008, 08:07 PM
Altzens,
No, I ment 'target="_top"'. If you do that, there's a flicker with that script (and also with John's, I'm afraid -- but not sure).
By the way, there's a beautyful XMLHttpRequest / iframe combo, see http://www.twinhelix.com

Good luck,
Arie,

jscheuer1
01-14-2008, 09:21 PM
Nope, no target anywhere in my code, or recommended for the markup used with it. However, when you say:


flicker on page transition

Do you mean proprietary filter transitions? All bets are off on that.

If you just mean what happens when you load a page and then refresh one of its frames or iframes, things will jump or whatever a little, yes. But this is meant to be a one time event to get the correct top page displaying if one of its external pages has been navigated to directly from a bookmark or offsite link.

The effect of refreshing an iframe is generally less jarring than that of refreshing a frame.

molendijk
01-14-2008, 10:02 PM
If you just mean what happens when you load a page and then refresh one of its frames or iframes, things will jump or whatever a little, yes. But this is meant to be a one time event to get the correct top page displaying if one of its external pages has been navigated to directly from a bookmark or offsite link.

OK, I see.

Arie

jscheuer1
01-14-2008, 10:25 PM
If even that is too much for you, you can make up a page that has only a blank page in the frame or iframe that will be filled, and use this page (identical in every other way to your regular top page) only for the purposes of en-framing 'orphans'.