一个JS对话框,可以显示其它页面,
还不能自适应大小
garyBox.js
// JavaScript Document //gary 2014-3-27 //实在不会用那些JS框架,自己弄个,我只是想要个可以加载其它页面的对话框而以 //关闭那两个字可能乱码,自己另存下,这个是utf8没问题 //调用 /// //<a href="#" onclick="showGaryBox(‘弹窗‘,‘http://www.baidu.com‘,function(){alert(‘窗口关闭!‘)})">弹窗</a> /// var garyBox ; var garyBoxHead; var garyBoxTitleText; var garyBoxClose; var garyBoxIframe; function createGaryBox() { document.body.innerHTML+="<div id=\"garyBox\" style=\"display:none\"><div id=\"garyBoxHead\"><h4 ><span id=\"garyBoxTitleText\">title</span></h4><h4><span id=\"garyBoxClose\">关闭</span></h4></div><div><iframe id=\"garyBoxIframe\" name=\"garyBoxIframe\" width=\"100%\" height=\"100%\" frameBorder=\"0\" frameSpacing=\"0\" scrolling=\"auto\" marginHeight=\"0\" marginWidth=\"0\" ></iframe></div></div>"; garyBox = document.getElementById("garyBox"); garyBox.style.cssText="border:1px solid #369;width:300px;height:150px;background:#e2ecf5;z-index:1000;position:absolute;display:none;"; garyBoxHead=document.getElementById("garyBoxHead"); garyBoxHead.style.cssText="height:20px;background:#369;color:#fff;padding:5px 0 0 5px;"; garyBoxTitleText=document.getElementById("garyBoxTitleText"); garyBoxTitleText.style.cssText="float:left;"; garyBoxClose = document.getElementById("garyBoxClose"); garyBoxClose.style.cssText="cursor:pointer;float:right; margin-right:10px;"; garyBoxIframe=document.getElementById("garyBoxIframe"); } function showGaryBox(title,url,onClose,width,height) { if(!garyBox)createGaryBox(); if(!arguments[3]) width = 600; if(!arguments[4]) height = 300; garyBoxTitleText.innerHTML=title; <!--设置遮敝--> garyBox.style.display = "block"; garyBox.style.position = "absolute"; garyBox.style.top = "50%"; garyBox.style.left = "50%"; garyBox.style.marginTop = -height/2; garyBox.style.marginLeft = -width/2; garyBox.style.width=width; garyBox.style.height=height; var garyBoxBg = document.createElement("div"); garyBoxBg.setAttribute("id","garyBoxBg"); garyBoxBg.style.background = "#000"; garyBoxBg.style.width = "100%"; garyBoxBg.style.height = "100%"; garyBoxBg.style.position = "absolute"; garyBoxBg.style.top = "0"; garyBoxBg.style.left = "0"; garyBoxBg.style.zIndex = "500"; garyBoxBg.style.opacity = "0.3"; garyBoxBg.style.filter = "Alpha(opacity=30)"; document.body.appendChild(garyBoxBg); document.body.style.overflow = "hidden"; garyBoxClose.onclick = function() { garyBox.style.display = "none"; garyBoxBg.style.display = "none"; if(onClose) { onClose(); } } garyBoxIframe.style.margin=0; garyBoxIframe.style.padding=0; garyBoxIframe.src=url; garyBoxIframe.onload=function(){ } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。