js implements web pages that are not nested within the iframe framework and several differences between ES2en.href

  • 2020-06-23 00:11:02
  • OfStack

First of all, we understand 1: window.location.href, location.href, self.location.href, parent. href, top.location
"window. location. href"," location. href", "self. location. href" are jumps to this page
"parent.location.href" is a jump to the top of the page
"top. location. href" is the outermost page jump

Here's an example (pictured above) :
If A B C, D are plain page, D C iframe, C B iframe, B A iframe,
If js in D writes like this:
"window. location. href"," location. href" : D page jump
"parent. location. href" : C page jump
"top. location. href" : A page jump

If form is on the D page:
< form > : form page jumps after submission
< form target="_blank" > : form submits and a new page pops up
< form target="_parent" > : form page jumps after submission
< form target="_top" > : form submitted A page jump

For page refresh, the D page reads as follows:
"parent. location. reload ();" : C page refresh (of course, you can also use the child window opener object for the parent window object: window. opener. document. location. reload (); )
"top. location. reload ();" : A page refresh

Looking back now, it's easy for js to implement the web page protection from the iframe framework. Assuming that the ES121en.html file frames the ES123en.html file, the idea goes like this: add js to content.html to check whether its own ES128en.location.href address is top.location.href address. If yes, it's not nested. If no, it's nested. That's one hint we can give. preview

Web page prevent frame method code:
 
<script language="javascript"> 
if(top.location!==self.location){ 
WarningTxt1 = "content The page is iframe ! "; 
WarningTxt2 = " We jump iframe , direct access content Page! "; 
alert(WarningTxt1); 
alert(WarningTxt2); 
top.location.href=self.location.href; 
} 
</script> 

Related articles: