解析js中获得父窗口链接getParent方法以及各种打开窗口的方法


Posted in Javascript onJune 19, 2013
//打开模态窗口
function dialog(obj){
if(obj.url == undefined || obj.url == null){
throw new Error("please set obj.url");
}
var url = obj.url;
if(url.indexOf("?")!=-1){
url = url+ "&r_=" + Math.random();
}else {
url = url+ "?r_=" + Math.random();
}
//alert(obj.width + "," + obj.height + "," + obj.top + "," + obj.left);
var w ;
if(!obj.width){
w = screen.width/2;
}else{
w = parseInt(obj.width);
}
var h ;
if(!obj.height){
h = 500;
}else{
h = parseInt(obj.height);
}
var t ;
if(!obj.top){
t = 50;
}else{
t = parseInt(obj.top);
}
var l;
if(!obj.left){
l = (screen.width - parseInt(w))/2;
}else{
l = parseInt(obj.left);
}
w = parseInt(w) + "px";
h = parseInt(h) + "px";
l = parseInt(l) + "px";
t = parseInt(t) + "px";
var paramStr = "";
paramStr += ("dialogHeight=" + h + ";");
paramStr += ("dialogWidth=" + w + ";");
if(obj.center != undefined && obj.center != null){
paramStr += "center=" + obj.center + ";"
}else{
paramStr += ("dialogTop=" + t + ";");
paramStr += ("dialogLeft=" + l + ";");
}
paramStr += "resizable=yes;scroll=yes";
//alert(paramStr);
var rv = window.showModalDialog(url,window,paramStr);
if (rv == undefined) {
  rv = window.returnValue;  
}
if(obj.cb){
return obj.cb.call(rv,rv);
}
return rv;
}
function openWin(u,w,h){
var obj = {
url : u,
width : w,
height : h
}
return dialog(obj);
}
function openWinWithCallBack(u,w,h,fun){
var obj = {
url : u,
width : w,
height : h,
cb : fun
}
return dialog(obj);
}
function openWindow(obj){
if(obj.url == undefined || obj.url == null){
throw new Error("please set obj.url");
}
var url = obj.url;
if(url.indexOf("?")!=-1){
url = url+ "&r_=" + Math.random();
}else {
url = url+ "?r_=" + Math.random();
}
//alert(obj.width + "," + obj.height + "," + obj.top + "," + obj.left);
var w ;
if(!obj.width){
w = screen.width/2;
}else{
w = parseInt(obj.width);
}
var h ;
if(!obj.height){
h = 500;
}else{
h = parseInt(obj.height);
}
var t ;
if(!obj.top){
t = 50;
}else{
t = parseInt(obj.top);
}
var l;
if(!obj.left){
l = (screen.width - parseInt(w))/2;
}else{
l = parseInt(obj.left);
}
w = parseInt(w);
h = parseInt(h);
l = parseInt(l);
t = parseInt(t);
//窗口句柄
var name;
if(!obj.name){
name = "win_" + new Date().getTime();
}else{
name = obj.name;
}
//alert(name);
//是否可以改变窗口大小
var resizable = obj.resizable || "no";
//是否有滚动条
var scrollbars= obj.scrollbars || "yes";
//是否有状态栏
var status = obj.status || "no";
//是否有菜单栏
var menubar = obj.menubar || "no";
//是否有工具栏
var toolbar = obj.toolbar || "no";
//是否有地址栏
var locations = obj.locations || "yes";
return window.open (url,name,"height=" + h + ",width=" + w +  ",top=" + t + ",left=" + l + ",toolbar=" + toolbar + ",menubar=" + menubar + ",scrollbars=" + scrollbars + ", resizable=" + resizable + ",location=" + locations + ", status=" + status + ",hotkeys=esc"); 
}
//模态窗口打开模式的子页面获取父页面对象
function getParent(){
var p = "";
if (window.opener != undefined) {
p = window.opener;
}
else {
p = window.dialogArguments;
};
return p;
}
//模态窗口打开模式的子页面设置returnValue
function setReturnValue(v){
if (window.opener != undefined) {
window.opener.returnValue = v;
}
else {
window.returnValue = v;
};
}
//滑动门
function ScrollDoor(){
this.value = 0;
}
ScrollDoor.prototype = {
onlyMenu : function(menus,openClass,closeClass){ // only menu no have content
var _this = this;
for(var i = 0 ; i < menus.length ; i++)
{ 
_this.$(menus[i]).flag = ++this.value;
_this.$(menus[i]).value = i;
_this.$(menus[i]).onclick = function(){
for(var j = 0 ; j < menus.length ; j++)
{ 
_this.$(menus[j]).className = closeClass;
//_this.$(divs[j]).style.display = "none";
} 
_this.$(menus[this.value]).className = openClass;
//_this.$(divs[this.value]).style.display = "block";
}
}
},
sd : function(menus,divs,openClass,closeClass){// two class
var _this = this;
if(menus.length != divs.length)
{
alert("菜单层数量和内容层数量不一样!");
return false;
} 
for(var i = 0 ; i < menus.length ; i++)
{ 
_this.$(menus[i]).flag = ++this.value;
_this.$(menus[i]).value = i;
_this.$(menus[i]).onclick = function(){
for(var j = 0 ; j < menus.length ; j++)
{ 
_this.$(menus[j]).className = closeClass;
_this.$(divs[j]).style.display = "none";
} 
_this.$(menus[this.value]).className = openClass;
_this.$(divs[this.value]).style.display = "block";
}
}
},
sd3class : function(menus,divs,openClass,closeClass,middleClass){ //three class
var _this = this;
for(var x = 0 ; x < menus.length ; x++)
{
_this.$(menus[x]).state = _this.$(menus[x]).className == openClass ?  "open" : "close";
}
if(menus.length != divs.length)
{
alert("菜单层数量和内容层数量不一样!");
return false;
} 
for(var i = 0 ; i < menus.length ; i++)
{ 
_this.$(menus[i]).flag = ++this.value;
_this.$(menus[i]).value = i;
_this.$(menus[i]).onclick = function(){
for(var j = 0 ; j < menus.length ; j++)
{
_this.$(menus[j]).className = closeClass;
_this.$(divs[j]).style.display = "none";
_this.$(menus[j]).state = "close";
}
this.state = "open";
_this.$(menus[this.value]).className = openClass;
_this.$(divs[this.value]).style.display = "block";
}
_this.$(menus[i]).onmouseover = function(){
//alert(this.state);
for(var j = 0 ; j < menus.length ; j++)
{ 
if(_this.$(menus[j]).state != "open")
{
_this.$(menus[j]).className = closeClass;
_this.$(menus[j]).state = "close";
} 
}
if(this.state == "open")
{
}
else
{
this.className = middleClass;
} 
}
_this.$(menus[i]).onmouseout = function(){
if(this.state != "open")
{
this.className = closeClass;
}
}
}
},
$ : function(oid){
if(typeof(oid) == "string")
return document.getElementById(oid);
return oid;
}
}
Javascript 相关文章推荐
jQuery powerFloat万能浮动层下拉层插件使用介绍
Dec 27 Javascript
Iframe自适应高度绝对好使的代码 兼容IE,遨游,火狐
Jan 27 Javascript
IE6下focus与blur错乱的解决方案
Jul 31 Javascript
js禁止页面刷新禁止用F5键刷新禁止右键的示例代码
Sep 23 Javascript
jquery实现input输入框实时输入触发事件代码
Jan 28 Javascript
angularjs基础教程
Dec 25 Javascript
JQuery中ajax方法访问web服务实例
Jul 18 Javascript
Ajax和Comet技术总结
Feb 19 Javascript
vue引入新版 vue-awesome-swiper插件填坑问题
Jan 25 Javascript
深入理解 Koa 框架中间件原理
Oct 18 Javascript
原生JS实现的自动轮播图功能详解
Dec 28 Javascript
基于javascript的无缝滚动动画1
Aug 07 Javascript
Js,alert出现乱码问题的解决方法
Jun 19 #Javascript
jquery拖动插件(jquery.drag)使用介绍
Jun 18 #Javascript
js实现屏蔽默认快捷键调用自定义事件示例
Jun 18 #Javascript
Jquery事件的连接使用示例
Jun 18 #Javascript
jquery属性过滤选择器使用示例
Jun 18 #Javascript
js实现的切换面板实例代码
Jun 17 #Javascript
javascript实现可改变滚动方向的无缝滚动实例
Jun 17 #Javascript
You might like
PHP性能优化准备篇图解PEAR安装
2011/12/05 PHP
ThinkPHP 连接Oracle数据库的详细教程[全]
2012/07/16 PHP
PHP中对缓冲区的控制实现代码
2013/09/29 PHP
PHP函数eval()介绍和使用示例
2014/08/20 PHP
PHP开发之归档格式phar文件概念与用法详解【创建,使用,解包还原提取】
2017/11/17 PHP
JavaScript 用Node.js写Shell脚本[译]
2012/09/20 Javascript
jquery动态添加删除div 具体实现
2013/07/20 Javascript
JavaScript遍历table表格中的某行某列并打印其值
2014/07/08 Javascript
js在指定位置增加节点函数insertBefore()用法实例
2015/01/12 Javascript
详解Bootstrap按钮
2016/01/04 Javascript
Node.js插件安装图文教程
2016/05/06 Javascript
前端框架Vue.js中Directive知识详解
2016/09/12 Javascript
深入浅析JS是按值传递还是按引用传递(推荐)
2016/09/18 Javascript
vue.js使用v-if实现显示与隐藏功能示例
2018/07/06 Javascript
Vue.js实现tab切换效果
2019/07/24 Javascript
vue2路由方式--嵌套路由实现方法分析
2020/03/06 Javascript
JavaScript 引用类型实例详解【数组、对象、严格模式等】
2020/05/13 Javascript
JS定时器如何实现提交成功提示功能
2020/06/12 Javascript
基于javascript canvas实现五子棋游戏
2020/07/08 Javascript
初步剖析C语言编程中的结构体
2016/01/16 Python
python模块简介之有序字典(OrderedDict)
2016/12/01 Python
Python爬虫实现(伪)球迷速成
2018/06/10 Python
python用plt画图时,cmp设置方法
2018/12/13 Python
Python3 关于pycharm自动导入包快捷设置的方法
2019/01/16 Python
python单向链表的基本实现与使用方法【定义、遍历、添加、删除、查找等】
2019/10/24 Python
Python如何基于rsa模块实现非对称加密与解密
2020/01/03 Python
关于python的缩进规则的知识点详解
2020/06/22 Python
全球知名巧克力品牌:Godiva
2016/07/22 全球购物
高性能装备提升营地:Kammok
2019/02/27 全球购物
给儿子的表扬信
2014/01/15 职场文书
社区学习党的群众路线教育实践活动心得体会
2014/11/03 职场文书
合作与交流自我评价
2015/03/09 职场文书
语文教师求职信范文
2015/03/20 职场文书
检讨书格式
2019/04/25 职场文书
MySQL入门命令之函数-单行函数-流程控制函数
2021/04/05 MySQL
搭建Yolov5服务器
2022/04/30 Servers