偶尔看到了document.referrer,之前一直有点疑惑与window.opener 和 window.parent之间的区别

首先查了一下w3cSCHOOL,

上面的解释:referrer 属性可返回载入当前文档的文档的 URL。

但是解释中没有写怎么载入才能用referrer,

翻看了几篇文章,终于搞懂了。

window.opener是当前页面A通过open方法弹出一个窗口B,那在B页面上 window.opener就是A

window.parent是当前页面C通过location.href转到新的页面D,那在D页面上window.parent就是B 或者是页面E里套一个frame为F,那F页面的window.parent就是E

referrer 描述: document对象的referrer属性,返回导航到当前网页的超链接所在网页的URL。

document.referrer的具体应用场景

如果要显示某一个网站的超链接跳转到你的网站你可以如下:

<script type="text/javascript">
var refurl=document.referrer;
if(refurl.indexOf("wowgame")>-1){
alert("你的来源网址为:【"+document.referrer+"】目前本站与该站已终止合作。");
location.replace(refurl);
}
</script>

js操作frame详细解说,window.opener和window.parent的区别

frame框架里的页面要改其他同框架下的页面或父框架的页面就用parent
window.opener引用的是window.open打开的页面的父页面。

window.frames对象可以引用iframe里的页面,也可以引用frameset里的页面.

可以这样

window.frames[0].document.getElementById('xx');

可以这样

window.frames[0].document.body.innerHTML;
frm = window.parent.window.frames['uploadFrame'];
frmDocument = frm.document;
frm.sb(3); //sb 是uploadFrame页面里的一个函数

对于firefox
如果你遇到报错:parent.document.frames has no properties
换为如下代码就可以了,这个代码IE,ff兼容. frm = window.parent.window.frames['uploadFrame'];其实 frames 集合并不是挂在 document 而是挂在 window 对象下.

注意这样修改frame里的页面有限制,就是必须是同域下的,否则无法访问
如果是同一域下,但是子域名不同,那么涉及到的js,html文件都加上一句。

document.domain = xxx.com [这里填写你的域名]

document.getElementById('iframeid').contentWindow.document.getElementById('someelementid');

document.referrer的使用和window.opener 跟 window.parent 的区别的更多相关文章

  1. window.opener和window.open的使用

    window.opener和window.open的使用 window.opener是指调用window.open方法的窗口.window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击 ...

  2. window.parent与window.opener、window.showModalDialog的区别 opener和showModalDialog刷新父页面的方法

    项目中使用案例: 父窗体 <s:form namespace="/forexagent" id="listSearchForm" name="t ...

  3. window.opener和window.open

    window.open (URL,name,specs,replace)方法用于打开一个新的浏览器窗口或查找一个已命名的窗口. URL:可选.打开指定的页面的URL.如果没有指定URL,打开一个新的空 ...

  4. js jquery 关闭弹出页面 并刷新父页面(window.opener)

    function Closepage() { if (window.opener && !window.opener.closed) { window.parent.opener.lo ...

  5. window.parent 与 window.opener

    window.parent针对iframe,window.opener针对window.open 父页面parent.jsp: <%@ page language="java" ...

  6. [转]window.opener用法

    window.opener 实际上就是通过window.open打开的窗体的父窗体. 比如在父窗体parentForm里面 通过 window.open("subForm.html" ...

  7. window.opener调用父窗体方法的用法

    应用实例:        function BindWindowCloss() {            $(window).bind('beforeunload', function () {    ...

  8. window.opener用法

    [转]window.opener用法 window.opener 实际上就是通过window.open打开的窗体的父窗体. 比如在父窗体parentForm里面 通过 window.open(&quo ...

  9. window.parent与window.opener的区别

    有这样一个需求,弹出一个新窗口 并从该新页面的select选择框中选择需要的类别,再返回到之前的父窗口页面的某个文本框中.这里就要用到window.parent和window.opener 如题两种方 ...

随机推荐

  1. 洛谷P4178 Tree (点分治)

    题目描述 给你一棵TREE,以及这棵树上边的距离.问有多少对点它们两者间的距离小于等于K 输入输出格式 输入格式:   N(n<=40000) 接下来n-1行边描述管道,按照题目中写的输入 接下 ...

  2. Vue--axios:vue中的ajax异步请求(发送和请求数据)、vue-resource异步请求和跨域

    跨域原理: 一.使用axios发送get请求 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 & ...

  3. VC6.0 如何显示代码行号

    VC6.0是一款比较经典.稳定的功能强大的IDE,目前也有很多人在使用.但美中不足的是它不能像其他IDE那样显示行号.这里需要用到一个插件VC6LineNumberAddin, 下载地址:http:/ ...

  4. memcached整理の基本使用

    memcached 客户端与服务器端的通信比较简单,使用的基于文本的协议,而不是二进制协议.(http 协议也是这样), 因此我们通过telnet 即可与memcached 作交互. # 格式teln ...

  5. [Erlang15]“hello world”与<<”hello world”>>的具体区别是什么?

    参见 :http://learnyousomeerlang.com/buckets-of-sockets 为了加深理解,自译如下,若理解有误或更好的建议,请帮忙指出, :) Buckets of So ...

  6. Transaction And Lock--已提交读快照

    --===================================================== --行版本控制已提交读ALTER DATABASE DB5 SET READ_COMMI ...

  7. CentOS 傻瓜式部署uWSGI + nginx + flask

    交代背景 这篇帖子是为了提供我自己的July Novel站点的小说数据支撑.解决分布式部署爬虫程序的繁琐过程,由于本人对shell编程并不熟悉,故而先逐步记录操作步骤,通过以下操作达到节省时间的方式. ...

  8. 201621123023《Java程序设计》第3周学习总结

    一. 本周学习总结 写出你认为本周学习中比较重要的知识点关键词,如类.对象.封装等 关键字:面向对象,类,对象,构造函数,封装,继承 用思维导图或者Onenote或其他工具将这些关键词组织起来 二.书 ...

  9. S:List

    描述 写一个程序完成以下命令:new id ——新建一个指定编号为id的序列(id<10000)add id num——向编号为id的序列加入整数nummerge id1 id2——合并序列id ...

  10. iOS 设备定位功能可用的判断

    if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] ...