JavaScript FAQ (10)--Framework (frame) __java

Source: Internet
Author: User

Viii. Framework

1. Is my page in the frame? (Is my page framed?)

Q: My page is the page in the frame, or the top window of the browser.

A: To test whether the page is in the frame, you can use the following conditional operator:

if (self.location!=top.location)//If yes, you ' re framed
if (self.location==top.location)//There you aren ' t framed

Example. Let's assume that your site uses a framework that provides some functional navigation (just like this site Suppose your top-level frameset (frameset) is in the file / . If a user accesses some pages that are not in the frame, what should be done? (This can happen if the user uses a search.) For this type of user, you may want to display a hyperlink to the top-level frameset-only when the page is not in the frame.

if (self.location==top.location) {
  //The page isn't in the frameset index.htm!!! 
 document.write (' <p><a href= '/index.htm ">home page</a> ')

A similar code is used on this page. If you open the page in the top-level window, you will see an extra Hyperlink content directory (Table of Contents) (just below the top of the page, just below the title). This hyperlink will take you back to the frame view.

2. Jump out of frame (breaking out of a frameset)

Q: Some malicious guys will load my pages from other sites into their frames. How can I jump out of these frameworks?

a: You just need to test whether your page is in the frame, as mentioned in the previous question. If so, you can easily jump out of the frame:

if (self.location!=top.location) top.location=self.location; 

However, use this tip sparingly-especially if your own site uses frames.



There are two things about this:

1. For standalone pages, you can use the above method

2. If the page is also in the frame, You can determine whether the name of the frame is the same as the preset:

if (!= "DD") top.location=self.location; 

3. Update two frames simultaneously (updating tow frames at a time?)

Q : Can I update two (or more) frames at the same time?

A : OK. The easiest way to update several frames at the same time is to use JavaScript functions to load new pages into the frame that is about to be updated. For example, if you have two frames, left, and right, then the same function that updates both frames is

function Updatebothframes () {
 Top.left.location= "newpage1.htm";
Top.right.location= "newpage2.htm"; 

This function can be invoked when the user presses a button or clicks a hyperlink. The following example shows the HTML code to create buttons and hyperlinks that call this function:

<a href= "Javascript:updatebothframes ()" >click here</a> <input Type=button value= "Press Me" onclick= "Updatebothframes ()" > 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.