js实现网页防止被iframe框架嵌套及几种location.href的区别
首先我们了解一下几种location.href的区别简单的说:几种location.href的区别js实现网页被iframe框架功能,感兴趣的朋友可以了解下
首先我们了解一下:window.location.href、location.href、self.location.href、parent.location.href、top.location.href他们的区别与联系,简单的说:几种location.href的区别 js实现网页被iframe框架功能
"window.location.href"、"location.href"、"self.location.href"是本页面跳转
"parent.location.href"是上一层页面跳转
"top.location.href"是最外层的页面跳转
举个例子说明(如上图):
如果A,B,C,D都是普通页面,D是C的iframe,C是B的iframe,B是A的iframe,
如果D中js这样写:
"window.location.href"、"location.href":D页面跳转
"parent.location.href":C页面跳转
"top.location.href":A页面跳转
如果D页面中有form的话:
<form>: form提交后D页面跳转
<form target="_blank">: form提交后弹出新页面
<form target="_parent">: form提交后C页面跳转
<form target="_top"> : form提交后A页面跳转
关于页面刷新,D 页面中这样写:
"parent.location.reload();": C页面刷新 (当然,也可以使用子窗口的 opener 对象来获得父窗口的对象:window.opener.document.location.reload(); )
"top.location.reload();": A页面刷新
现在回头看看,js实现网页防止被iframe框架功能就很简单了。假设frame.html文件中框架了content.html文件,那么思路是这样的:在content.html中加入js检测自己本身top.location.href地址,是否为top.location.href地址。如果是则没被嵌套,如果否的话即被嵌套了,这是我们可以提示一下。预览效果
网页防止被框架方法代码:
if(top.location!==self.location){
WarningTxt1 = "content页面被iframe了!";
WarningTxt2 = "我们跳出iframe,直接访问content页面吧!";
alert(WarningTxt1);
alert(WarningTxt2);
top.location.href=self.location.href;
}
</script>
js实现网页防止被iframe框架嵌套及几种location.href的区别的更多相关文章
- js 跨域 Jquery取得iframe中元素的几种方法
http://www.jb51.net/article/34942.htm 收集利用Jquery取得iframe中元素的几种方法 : 父页面访问子页面 $(document.getElementByI ...
- JS 中document.URL 和 window.location.href 的区别
实际上,document 和 window 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,window 表示一个窗口对象. 一个窗口下面可以有很多的documen ...
- iframe框架嵌套技巧(全屏,去双滚动条)
一般情况下我们很少用到iframe(框架),但有些特殊的情况下我们不得不使用iframe,那么或许或遇到嵌套内容不全屏,网页周围有边框,双滚动条等等情况,下面来说一下处理技巧. 全屏与边框处理: &l ...
- JS操作网页中的iframe
/* *parent.html */ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...
- JS中 window.location 与window.location.href的区别
疑惑:window.location='url' 与window.lcoation.href='url'效果一样,都会跳转到新页面,区别在哪?查得的资料如下: 1:window.location是页 ...
- JS 中document.URL 和 windows.location.href 的区别
实际上,document 和 windows 这两个对象的区别已经包含了这个问题的答案. document 表示的是一个文档对象,windows 表示一个窗口对象. 一个窗口下面可以有很多的docu ...
- js如何判断是否在iframe中及防止网页被别站用 iframe嵌套 (Load denied by X-Frame-Options)
1. js如何判断是否在iframe中 //方式一 if (self.frameElement && self.frameElement.tagName == "IFRAME ...
- js 控制框架页面跳转 top.location.herf = "url"
top.location.href和localtion.href有什么不同 top.location.href=”url” 在顶层页面打开url(跳出框架) self.locatio ...
- js中top.location.href、parent.location.href用法
window.location.href.location.href是本页面跳转 parent.location.href是上一层页面跳转 top.location.href是最外层的页面跳转 举例说 ...
随机推荐
- 【转】IOS开发中图片资源使用png还是jpg格式
对于iOS本地应用程序来说最简单的答案就是始终使用PNG,除非你有非常非常好的理由不用它. 当iOS应用构建的时候,Xcode会通过一种方式优化.png文件而不会优化其它文件格式.它优化得相当的好 他 ...
- C++语言-01-简介
简介 C++语言是C语言的超集,它扩充和完善了C语言:C++语言是一种静态类型的.编译时的.跨平台的.不规则的中级编程语言,综合了高级语言和低级语言的特点 C++支持的编程类型 面向对象编程 过程化编 ...
- Swift中的类和结构体的相同点与不同点
相同点: 1.都是有内部变量和函数 2.都可以有内部下标方式去取属性 3.都可以有初始化函数 4.都可以用协议 不同点: 1.类有继承 2.类可以多重引用 3.类有析构
- ASCII
0. American Standard Code of Information Interchange 美国信息交换标准码, 即ASCII, 定义表如下: Bin(二进制) Oct(八进制) Dec ...
- JavaScript Patterns 2.8 Number Conversions with parseInt()
Strings that start with 0 are treated as octal numbers (base 8) in ECMAScript 3; however, this has c ...
- C# listview 拖动节点
/// <summary> /// 当拖动某项时触发 /// </summary> /// <param name="sender"></ ...
- ThinkPHP 获取get post参数与I方法
传统方式获取变量 $id = $_GET['id']; // 获取get变量 $name = $_POST['name']; // 获取post变量 $value = $_SESSION['var'] ...
- cocos2d-x之初试内存管理机制
bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getIn ...
- mysql大小写问题
以前做企业项目的时候,用的都是oracle数据库,在新公司项目用的是mysql,有关mysql大小写的问题 1 windows下默认mysql是不区分大小写的,要想让其支持大小写.更改方法 在my ...
- k-means算法初识
基础知识: K-means聚类算法 聚类,简单地说就是把相似的东西分到一组.同 Classification (分类)不同,对于一个 classifier ,通常需要你告诉它“这个东西被分为某某类”. ...