Solved

Force Page to load in _top

Posted on 1997-05-02
9
247 Views
Last Modified: 2012-05-04
For various reasons, and various users, a certain page of mine is sometimes accidentally getting loaded within a frame.  This particular page looks REALLY bad within a frame.  I was wondering if there was a tag or Jscript (both IE and Netscape compatible) that would force my page to load as a parent document even if someone is loading it from within their frame.
0
Comment
Question by:willman
  • 4
  • 4
9 Comments
 

Expert Comment

by:salt032897
ID: 1836186
If you load your page in a framed environment, then you could
put a refresh statement in your pages to call your main page to _TOP.  Even call another frameset.

The refresh scheme will not work unless the framed page is loaded, someone loads/inks to it. If you put the meta refresh statement in your main page it might continually reload unless you put a loop="0" clause, or loop="no" either clause may not work. (I would not try the refresh clause on my main page.)

This META tag is to be used in a framed environment. The content="1 part of the statement is to set the
time factor for the refresh statement. The URL=page2.html" is your target or main page.

Frame loads two pages. when section two loads, it calls a refresh statement that calls your main document to the _top.

<META HTTP-EQUIV=REFRESH CONTENT="1; URL=page2.html">

Your frameset can be something like this:

<html>
<head><title>frame to reload page</title></head>
<frameset rows="98%,*">
<frame src="main.html" name="main" scrolling=auto noresize >
<frame src="reload.html" name="active" order="no">
</frameset>
</html>

You put the refresh meta statement in reload.html

refresh.html would read something like this:

<META HTTP-EQUIV=REFRESH CONTENT="1; URL=main.html" target="_top">

<!________________>
The following line will give the person reading your page the manual option of breaking out of the frame if the refresh scheme does not work.

<A HREF="main.html" target="_top">Home</A>
<!_________________>

You could place this "_target" statement on all your links to always break out of frames whenever someone applies one of your links  too. It is an easy way but does not automatically happen when your initial page is loaded.

<A HREF="document2.html" target="_top">Break out of frame</A>
<!____________>

I have not tried the meta statement because I really do not mind someone linking to my pages. Does your page have your identity
stamps on them? copyright, mailto, other important page links?

This question was asked earlier.
0
 
LVL 2

Author Comment

by:willman
ID: 1836187
This just makes the page continuously reload.  It does break out of the frame, but the page continues to reload.  This is not an acceptable solution.
0
 
LVL 4

Expert Comment

by:jshamlin
ID: 1836188
Pass the following fucntion to the browser onLoad - it will check to see if the parent location is the same URL as the document itself and, if not, will load the document into the parent frameset (if a frameset is nested inside a frameset, it will function recursively)

if (parent.document.location != 'page_URL'){
      parent.document.location = 'page_URL';
   }

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:willman
ID: 1836189
Nope -- In Internet Explorer, this produces an error that this object does not have the specified property (or something like that).  In Netscape, this still causes the page to continuously reload.
0
 

Expert Comment

by:salt032897
ID: 1836190
Hi willman,

The page will continually reload if the refresh statement is on the page being reloaded. Reason for he framed environment.

Which page is being sent to _top?  Should be your main.html. the frameset is now gone as well as refresh.html.   The frame loads, refresh.html calls your main page to _top.  As your page is now on top, with no refresh statement, how could it reload?
 

Comment your code back, so we can review it. there should be at least three pages:
1.  frameset.html
2.  main.html <!empty doc is fine.>
3.  refresh.htm.
0
 
LVL 2

Author Comment

by:willman
ID: 1836191
I have fiddled a little, and this is the result:

index.html (my default document):
<META HTTP-EQUIV=REFRESH CONTENT="1; URL=main.html" target="_top">

main.html:
bunch of stuff

The result:  It now works fine for those linking directly to the page(it no longer continuously reloads).  However, for those who are linking from a frame, it does not break out of the frame (it seems to be ignoring the TARGET command.
0
 

Accepted Solution

by:
salt032897 earned 200 total points
ID: 1836192
From what I see, you are loading your index file which then calls your main doc to the top.  This will work so long as they call your index or leader file.whatever

you may want to give your leading.doc some other name which can include uppercase letters to make it just a bit more difficult to load the page indirectly.

Anyway, I just got a newsletter that should solve your problem. It is part of a document Chuch Musiano wrote for Netscape World which says that this problem can only be solved using java.  hmmm.

The Java script first checks to see if it is loaded in a framed environment.  If so, it call the second part of the scheme to break out to top.

Try the link to the page and see if it makes sense.  




"

http://www.netscapeworld.com/netscapeworld/nw-05-1997/nw-05-html.html

Collecting all my favorite pieces of the puzzle, I offer this version of the <body> tag to frame-proof your pages:

     <body onLoad="if (self != top) top.location = self.location">

"

Seems simple enough, his claims are on the link.  
0
 

Expert Comment

by:salt032897
ID: 1836193
Hey willman,

Here is the text of the netscapeworld document, as referenced above.

<"quote>

Stop the barrage of e-mail! I give: you can frame-proof your pages, keeping them from being captured by the frames on another page that links to your site.
     In my defense, I did claim that frame-proofing is impossible using HTML. All the solutions I received used JavaScript to escape from frames. Since
     JavaScript is technically not part of HTML, I feel somewhat vindicated that my answer was correct, although of little use to the majority of my readership.

     To recap, a reader wrote complaining that their beautiful pages were being referenced from within frames on other sites. On those sites, the link to their site
     did not contain a target=_top attribute, causing their pages to be squeezed into a frame within the linking page. The result was ugly and bothersome,
     especially since the reader's pages were being diminished by someone else's HTML shortcomings. How could he keep this from happening?

     The answer lies not in HTML, but in JavaScript. It only takes a few lines of JavaScript to detect the presence of frames and to then remove them.

     I was struck by how many different ways authors had come up with to detect that frames were being used on the current page. All of the following JavaScript
     conditional expressions will test to see if frames are in use:
          if (self.location != top.location)
          This tests to see if the document location of the current document matches the location of the top-most document on the page. If frames are being
          used, that top-most document will have a different URL and the test will succeed. If there are no frames, the top document and the current document
          are the same object and have the same location URL, indicating that frames are not being used.

          if (self != top)
          This is a more general version of the first condition. Instead of testing the document location, simply check to see if the current document is the same
          object as the top document on the page. If not, frames are being used.

          if (top.frames.length > 0)
          The top document has an object that contains all the frames in use on the page. Within that object, the length member keeps a count of how many
          frames are currently defined. If that count is greater than zero, frames are being used. It is also possible (and more elegant) to write this condition
          simply as top.frame.length. Since any non-zero value in JavaScript (like C) is equal to "true", a non-zero frame count returns a true value as well.

          if (top.frames[0].name != "name")
          This is a more specific test that only works if your page contains its own frames. In that case, you can test the name of a specific frame to see if it
          matches that frame in your document. You'll need to replace the 0 in the condition with the number of a suitable named frame in your document, and
          replace the "name" with the name of the frame. If the names don't match, your frames have been captured within another set of frames.

     Once you detect that they are in use, breaking free is easy. Simply set top.location to your document's URL. When this property is changed, the browser
     will reload the document into the top-level browser display, removing all the frames and replacing them with your document.

     Readers were split in setting top.location, relying on two principal methods:

     top.location = "URL";
     top.location = self.location;

     The first sets the location to an explicit URL which you must provide. The second uses the URL of the current page. I prefer the second method, since you
     need not ever update the URL if the page moves or changes its name. The first version will require ongoing maintenance as your site grows and evolves.

     The last piece to the puzzle is adding this snippet of code to your documents. We put this down with the onLoad attribute of the <BODY> tag. The JavaScript
     fragment assigned to this attribute is executed as the page is initially loaded by the browser. This means that the page can detect the presence of frames
     almost immediately, before your page is fully presented to the user. Since a change to the top.location property results in an immediate reload, you'll
     break free of the frames almost instantly.

     Collecting all my favorite pieces of the puzzle, I offer this version of the <body> tag to frame-proof your pages:

     <body onLoad="if (self != top) top.location = self.location">

     Add all the other attributes to it, of course, and give it a try in your pages. If it doesn't work, I'm sure to hear about it.

</quote">

salt
0
 
LVL 2

Author Comment

by:willman
ID: 1836194
Thanks, that is exactly the solution I was looking for.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
div to fit another div 8 28
Html fieldset fix its height and width 4 34
How to display div value on input field value in php 11 54
How to create a table with buttons 3 23
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question