Solved

Force Page to load in _top

Posted on 1997-05-02
9
238 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now