homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Prevent Pages From Opening Without Frames
Is this possible in a normal html website?
HolyDoom Witch

 1:24 am on Sep 5, 2010 (gmt 0)


I am not a coder (not even an html one). All I want to know, that is there a way to prevent the html pages from opening without frames meant to be seen only in a frame, say like from search engines, or from directly typing the address?

In a frameset, a page my videos.html opens like this:
www.Domain.com/ (The name of the html page is not visible. The page has opened in its frame.)

But in the situation I seek to correct, the page opens like this:
www.Domain.com/my videos.html (No frames are visible, only the whole page. For a site, this seems orphaned.)





 2:04 am on Sep 5, 2010 (gmt 0)

Hello HolyDoom Witch, and welcome to the forums.

Yes, you can do this with some JavaScript. I explained the basics here: Handy Generic JavaScript Coding [webmasterworld.com]. Loook for the post with the title

Since you "are not a coder" you may want to tap someone who understands a bit of coding to help. But the instructions in that thread are really straightforward. Many people often over-think it, but the instructions do work exactly as described.

HolyDoom Witch

 5:53 pm on Sep 5, 2010 (gmt 0)

I added this:
passpage = document.URL
if (top.location == self.location)
location.replace("master.html?" + passpage)

Now, after the question mark, I tried inserting the directory many ways, but somehow the script is showing in the page itself when I press F12 to test in Opera. I have created the master.html page in the public_html directory already.

I tried inserting the script:
1. before & after <html>
2. before & after <head> (I guess we have to place it after this.)

But it still shows in the page. It is just plain text till now. Of course there is something I don't understand.


Expression Web 4 Trial
XP 64-bit
Java installed


 8:15 pm on Sep 5, 2010 (gmt 0)

Did you create the new page master.html as described in that post?

HolyDoom Witch

 8:52 am on Sep 6, 2010 (gmt 0)

As you can see above, I already mentioned that.



 6:22 pm on Sep 6, 2010 (gmt 0)

Sorry for the misunderstanding - I meant did you follow the exact details of how to create that page.

What is not clear to me is what you mean by "I tried inserting the directory many ways" - what "directory" are you speaking of?


 9:01 am on Sep 7, 2010 (gmt 0)

I used to use similar code (many years back) but I seem to recall Opera was always a problem. If it works in IE and Firefox, you're probably doing it right.

Incidentally if (top==self) always worked fine for me.


HolyDoom Witch

 5:10 pm on Sep 7, 2010 (gmt 0)

By 'directory', I mean the filename including the path. Whatever code you have provided for the master.html, I inserted in a blank page (at the indicated spot), and tried testing the child document alone, to see if it opens in a frame instead of opening alone. But as I said, the code is visible near the heading of the page.

I also don't understand exactly where I have to insert the filename.

passpage = document.URL
if (top.location == self.location)
location.replace("master.html?" + passpage)

In the above code, I insert my page name after the question mark.

And yes, it's the same in IE8 too.



 6:14 pm on Sep 7, 2010 (gmt 0)

In the above code, I insert my page name after the question mark.

You don't need to do that.

"passpage" is a variable. The earlier part of the script automatically assigns it the value of the fragment page's address. The script handles it all, so you don't need to insert the actual file name anywhere.

The script will handle an indefinite number of files this way, without any concern on your part for inserting the actual file name.


 11:42 pm on Sep 7, 2010 (gmt 0)

I would use the following...
<script type="text/javascript">
if (top==self) { location.replace("master.html?" + location.href) }

Actually, I wouldn't use this, I would use frameless frames but that's a whole lot more complicated.



 2:44 am on Sep 8, 2010 (gmt 0)

Yes, that is simpler. I wrote the script the way I did back in 2001 so that the individual steps in logic stood out a bit more for the reader.

The exact way it appears there, with all the apparent redundancy, does work in Opera - or at least it did. I haven't used it for a good while now.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved