六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 48|回复: 0

基于frame的弹出框

[复制链接]

升级  92%

10

主题

10

主题

10

主题

童生

Rank: 1

积分
46
 楼主| 发表于 2013-2-1 09:56:41 | 显示全部楼层 |阅读模式
自己写了个基于frame的弹出框,解决了参数的传递,先记录下来,以便于以后自己下载!
效果如下:


/** * author: code by ShareMu */ //获得顶层窗口对象var topWindow = (function(p, c) {while (p != c) {c = pp = p.parent}return c})(window.parent, window);//弹出窗口方法function ShowModelDialog(url, titletext, backFn, width, height, params) {var msgw, msgh, bordercolor;msgw = (width ? width : 600);// 提示窗口的宽度msgh = (height ? height : 400);// 提示窗口的高度bordercolor = "#336699";// 提示窗口的边框颜色titlecolor = "#99CCFF";// 提示窗口的标题颜色var sWidth, sHeight;var thisW = topWindow;sWidth = thisW.document.documentElement.clientWidth;sHeight = thisW.document.documentElement.clientHeight;// 背景divvar bgDivId = getRandomStr(16, true, true, true);var bgObj = new Element("div");bgObj.setAttr("id", bgDivId);bgObj.addStyle("position", "absolute");bgObj.addStyle("top", "0");bgObj.addStyle("background", "#777");bgObj.addStyle("opacity", "0.6");bgObj.addStyle("left", "0");bgObj.addStyle("width", "100%");bgObj.addStyle("height", sHeight);bgObj = bgObj.element;thisW.document.body.appendChild(bgObj);var iframeObj = new Element("iframe");var iframeObjId = getRandomStr(16, true, true, true);iframeObj.setAttr("id", iframeObjId);iframeObj.setAttr("name", "ifname");iframeObj.addStyle("position", "absolute");iframeObj.addStyle("top", "25px");iframeObj.addStyle("filter", "Chroma(Color=white)");iframeObj.addStyle("zIndex", "10000");iframeObj.addStyle("width", "100%");iframeObj.addStyle("left", "0");iframeObj.addStyle("scrolling", "auto");iframeObj.addStyle("height", msgh);if(url){if(params){if(url.indexof("?")!=-1){url = url+"&"+params;}else{url = url+"?"+params;}}iframeObj.setAttr("src", url);}iframeObj = iframeObj.element;iframeObj.style.border = "0";iframeObj.style.background= "white";// 消息divvar msgDivId = getRandomStr(16, true, true, true);var msgObj = thisW.document.createElement("div")msgObj.setAttribute("id", msgDivId);msgObj.setAttribute("align", "center");msgObj.style.position = "absolute";msgObj.style.background = "white";msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";msgObj.style.width = msgw + "px";msgObj.style.height = (msgh + 24) + "px";var toph=sHeight - msgh;if(toph<0){toph = 0;}msgObj.style.top = (thisW.document.documentElement.scrollTop + toph/ 2)+ "px";msgObj.style.left = (sWidth - msgw) / 2 + "px";msgObj.style.zIndex = "1000";// 消息标题var msgTitleId = getRandomStr(16, true, true, true);var titleTable =  thisW.document.createElement("div");//var titleTableTR =  thisW.document.createElement("div");var titleTableMsgTD =   thisW.document.createElement("div");var closeTD =  thisW.document.createElement("div");titleTable.style.zIndex = "1000";titleTable.id = msgTitleId;titleTable.style.width = msgw-5;titleTableMsgTD.style.width = msgw-2;closeTD.style.right = "5";closeTD.style.top = "0";titleTable.style.display="inline";titleTable.style.border = "1px solid " + titlecolor;//titleTable.style.cursor = "pointer";closeTD.style.position = "absolute";titleTableMsgTD.setAttribute("align", "left");titleTableMsgTD.style.height = "24";titleTableMsgTD.style.border = "1px solid " + titlecolor;titleTable.setAttribute("align", "left");closeTD.setAttribute("align", "right");titleTable.style.background = bordercolor;titleTable.style.color = "white";var msgtitleTableIdl = getRandomStr(16, true, true, true);titleTableMsgTD.innerHTML = (titletext?titletext:"弹出框");titleTableMsgTD.style.margin = "0";//titleTableMsgTD.innerHTML = "弹出框"; closeTD.style.cursor = "pointer";closeTD.innerHTML = "关闭";closeTD.onclick = function() {var rvalue = thisW.frames[iframeObjId].returnValue;if (backFn) {backFn(rvalue);}thisW.document.body.removeChild(bgObj);thisW.document.getElementById(msgDivId).removeChild(titleTable);thisW.document.body.removeChild(msgObj);}closeTD.style.margin = "0";titleTable.appendChild(titleTableMsgTD);titleTable.appendChild(closeTD);msgObj.appendChild(titleTable);msgObj.appendChild(iframeObj);thisW.document.body.appendChild(msgObj);//alert(thisW.document.getElementById(msgTitleId).id);}function Element(type, paret) {this.element = topWindow.document.createElement(type);}Element.prototype.setAttr = function(name, value) {this.element.setAttribute(name, value);}Element.prototype.addStyle = function(name, value) {eval("this.element.style." + name + "=\"" + value + "\";");}//获得随机字符串 元素IDfunction getRandomStr(str_0, str_1, str_2, str_3) {var seed_array = new Array();var seedary;var i;seed_array[0] = ""seed_array[1] = "a b c d e f g h i j k l m n o p q r s t u v w x y z";seed_array[2] = "a b c d e f g h i j k l m n o p q r s t u v w x y z";seed_array[3] = "0 1 2 3 4 5 6 7 8 9";if (!str_1 && !str_2 && !str_3) {str_1 = true;str_2 = true;str_3 = true;}if (str_1) {seed_array[0] += seed_array[1];}if (str_2) {seed_array[0] += " " + seed_array[2];}if (str_3) {seed_array[0] += " " + seed_array[3];}seed_array[0] = seed_array[0].split(" ");seedary = ""for (i = 0; i < str_0; i++) {seedary += seed_array[0][Math.round(Math.random()* (seed_array[0].length - 1))]}return (seedary);}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表