Differences between several location. href Methods JS implements web pages to prevent nested functions by IFRAME framework

Source: Internet
Author: User

First, let's take a look at window. location. href, location. href, self. location. href, parent. location. href, top. location. href:
"Window. Location. href", "location. href", and "self. Location. href" are displayed on the current page.
"Parent. Location. href" is the previous page Jump
"Top. Location. href" is the outermost page Jump

Example(For example ):
If A, B, C, and D are common pages, D is the IFRAME of C, C is the IFRAME of B, and B is the IFRAME of,
If Js in D is written like this:
"Window. Location. href", "location. href": D page Jump
"Parent. Location. href": C page Jump
"Top. Location. href": a page Jump

If form exists on Page D:
<Form>: Jump to the D page after the form is submitted
<Form target = "_ blank">: a new page is displayed after the form is submitted.
<Form target = "_ parent">: C page jump after form is submitted
<Form target = "_ top">: Jump to page a after form is submitted

For page refresh, write the following in page D:
"Parent. location. reload (); ": refreshes the C page (of course, you can also use the opener object of the Child Window to obtain the parent window object: zookeeper opener.doc ument. location. reload ();)
"Top. Location. Reload ();": page a is refreshed.

Now let's take a look at it. It's easy to implement the function of JavaScript to prevent webpages from being put into the IFRAME framework. If the framework of the content.html file is set in the frame.html file, the idea is as follows: add Js in content.html to check whether the top. Location. href address is the top. Location. href address. If yes, It is not nested. If no, It is nested. This is a prompt.Preview Effect

Download source file

Code of the method to prevent web pages from being framed:
<Script language = "JavaScript">
If (top. location! = Self. Location ){
Warningtxt1 = "the content page is IFRAME! ";
Warningtxt2 = "Let's jump out of IFRAME and access the content page directly! ";
Alert (warningtxt1 );
Alert (warningtxt2 );
Top. Location. href = self. Location. href;
}
</SCRIPT>

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: info-contact@alibabacloud.com 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.