解析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 相关文章推荐
用js判断浏览器是否是IE的比较好的办法
May 08 Javascript
javascript实现的在当前窗口中漂浮框的代码
Mar 15 Javascript
window.open不被拦截的实现代码
Aug 22 Javascript
深入Javascript函数、递归与闭包(执行环境、变量对象与作用域链)使用详解
May 08 Javascript
bootstrap实现弹窗和拖动效果
Jan 03 Javascript
JavaScript实现iframe自动高度调整和不同主域名跨域
Feb 27 Javascript
JavaScript实现Fly Bird小游戏
Dec 15 Javascript
Bootstrap源码解读表单(2)
Dec 22 Javascript
React复制到剪贴板的示例代码
Aug 22 Javascript
JS中数据结构之栈
Jan 01 Javascript
详解vue路由篇(动态路由、路由嵌套)
Jan 27 Javascript
手写实现JS中的new
Nov 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中的一个中文字符串截取函数
2007/02/14 PHP
PHP实现的英文名字全拼随机排号脚本
2014/07/04 PHP
Smarty中调用FCKeditor的方法
2014/10/27 PHP
CI框架中cookie的操作方法分析
2014/12/12 PHP
AutoSave/自动存储功能实现
2007/03/24 Javascript
10个基于jQuery或JavaScript的WYSIWYG 编辑器整理
2010/05/06 Javascript
JavaScript对象之深度克隆介绍
2014/12/08 Javascript
webapp框架AngularUI的demo改造之路
2014/12/21 Javascript
Javascript 拖拽雏形中的一些问题(逐行分析代码,让你轻松了拖拽的原理)
2015/01/23 Javascript
纯Javascript实现ping功能的方法
2015/03/20 Javascript
jQuery插件Slider Revolution实现响应动画滑动图片切换效果
2015/06/05 Javascript
基于Javascript实现返回顶部按钮
2016/02/29 Javascript
详解JavaScript中数组和字符串的lastIndexOf()方法使用
2016/03/13 Javascript
node实现定时发送邮件的示例代码
2017/08/26 Javascript
微信小程序实现多选功能
2018/11/04 Javascript
在Vue中用canvas实现二维码和图片合成海报的方法
2019/06/10 Javascript
解决antd的Form组件setFieldsValue的警告问题
2020/10/29 Javascript
[01:56]林书豪DOTA2上海特级锦标赛励志短片
2016/03/05 DOTA
[01:01:51]EG vs VG Supermajor小组赛B组 BO3 第二场 6.2
2018/06/03 DOTA
[50:44]DOTA2-DPC中国联赛 正赛 SAG vs Dragon BO3 第二场 2月22日
2021/03/11 DOTA
python安装教程 Pycharm安装详细教程
2017/05/02 Python
详解用TensorFlow实现逻辑回归算法
2018/05/02 Python
Python+OpenCV采集本地摄像头的视频
2019/04/25 Python
基于django传递数据到后端的例子
2019/08/16 Python
详解查看Python解释器路径的两种方式
2020/10/15 Python
详解CSS3的box-shadow属性制作边框阴影效果的方法
2016/05/10 HTML / CSS
美国首屈一指的礼品篮供应商:GiftTree
2018/01/06 全球购物
泰国办公用品购物网站:OfficeMate
2018/02/04 全球购物
联想新西兰官方网站:Lenovo New Zealand
2018/10/30 全球购物
2014年教师党员公开承诺书
2014/05/28 职场文书
机械设计专业大学生职业生涯规划书范文
2014/09/13 职场文书
2014年优秀党员材料
2014/12/18 职场文书
材料员岗位职责
2015/02/10 职场文书
教师自荐信范文
2015/03/06 职场文书
简历中的自我评价应该这样写!
2019/07/12 职场文书
详解GaussDB for MySQL性能优化
2021/05/18 MySQL