jQuery弹出层,兼容ie,Firefox,谷歌浏览器
2010-07-31 14:20
447 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery弹出层</title>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script>
function test(url){//URL:弹出层地址
$("#work").css({display:"block"});
$("#work").load(url);
var winwidth=document.body.offsetWidth;//可以给弹出层定位
var winheight=document.body.offsetHeight;
var cenleft=winwidth/2-parseInt(document.getElementById("work").style.width)/2;
var centop=winheight/2-parseInt(document.getElementById("work").style.height)/2;
document.getElementById("work").style.left=cenleft+'px';
document.getElementById("work").style.top=centop+'px';
}
function close2(){
$("#work").css({display:"none"});
$("#work").html("");
}
function add_css(){//给弹出层加css,如果在弹出层里加css,在谷歌浏览器要删除弹出层的<body>
var str_css = "@import url(css/items.css);"; //定义内容
try { //IE下可行
var style = document.createStyleSheet();
style.cssText = str_css;
}
catch(e){ //Firefox,Opera,Safari,Chrome下可行
var style = document.createElement("style");
style.type = "text/css";
style.textContent = str_css;
document.getElementsByTagName("HEAD").item(0).appendChild(style);
}
}
</script>
</head>
<body>
<a href="#" onclick="test('my_items.html');add_css();">点击</a>
<script language="javascript" src="loadHtml.js"></script>
</body>
</html>
---------------------------------------------------------------------------
---------------------------------------------------------------------------
loadHtml.js:
document.writeln("<div id='work' style='z-index:9999;display:none; width:1000px; height:249px; border: 0px solid red;position:absolute;top:expression((document.documentElement.clientHeight-this.offsetHeight)/3);left:expression((document.documentElement.clientWidth-this.offsetWidth)/2);'></div>");
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery弹出层</title>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script>
function test(url){//URL:弹出层地址
$("#work").css({display:"block"});
$("#work").load(url);
var winwidth=document.body.offsetWidth;//可以给弹出层定位
var winheight=document.body.offsetHeight;
var cenleft=winwidth/2-parseInt(document.getElementById("work").style.width)/2;
var centop=winheight/2-parseInt(document.getElementById("work").style.height)/2;
document.getElementById("work").style.left=cenleft+'px';
document.getElementById("work").style.top=centop+'px';
}
function close2(){
$("#work").css({display:"none"});
$("#work").html("");
}
function add_css(){//给弹出层加css,如果在弹出层里加css,在谷歌浏览器要删除弹出层的<body>
var str_css = "@import url(css/items.css);"; //定义内容
try { //IE下可行
var style = document.createStyleSheet();
style.cssText = str_css;
}
catch(e){ //Firefox,Opera,Safari,Chrome下可行
var style = document.createElement("style");
style.type = "text/css";
style.textContent = str_css;
document.getElementsByTagName("HEAD").item(0).appendChild(style);
}
}
</script>
</head>
<body>
<a href="#" onclick="test('my_items.html');add_css();">点击</a>
<script language="javascript" src="loadHtml.js"></script>
</body>
</html>
---------------------------------------------------------------------------
---------------------------------------------------------------------------
loadHtml.js:
document.writeln("<div id='work' style='z-index:9999;display:none; width:1000px; height:249px; border: 0px solid red;position:absolute;top:expression((document.documentElement.clientHeight-this.offsetHeight)/3);left:expression((document.documentElement.clientWidth-this.offsetWidth)/2);'></div>");
相关文章推荐
- 遮罩层效果 兼容ie firefox jQuery遮罩层 弹出层带关闭按钮
- 兼容IE和Firefox的可拖动弹出登陆窗口
- 利用AJAX,得到XML和JSON信息,不用JQuery等UI框架,兼容 IE、Firefox、Chrome、Safari、Opera 等浏览器。
- jquery 层相对于游览器垂直中齐(兼容firefox 和ie)
- jQuery上传图片预览,简洁版,可兼容IE和FIREFOX
- 弹出窗口返回值---IE和firefox兼容
- JQuery 制作的一款在线编辑器(xheditor)。兼容IE,Firefox...感觉不错
- 利用jQuery srollTop()函数实现类似锚点的定位效果-兼容chrome,firefox,IE,safari
- 通用弹出层页面(兼容IE、firefox)可关闭控制宽高及屏蔽背景
- jquery.each兼容IE,firefox
- java版 jquery uploadify 通过Flash实现多文件上传 IE 和FireFox 兼容
- js右下弹出消息框,兼容ie,firefox
- javascript用div模拟Alert警告框,渐变弹出。兼容IE,firefox
- jQuery 祝福/许愿墙 开源版发布,兼容 IE,Firefox,有 php,asp,asp.net三种版本
- js实现鼠标右键自定义菜单(弹出层),并与树形菜单(TreeView)、iframe合用(兼容IE、Firefox、Chrome)
- jquery下拉菜单效果(超简洁实用,兼容IE和firefox等主流浏览器)
- Jquery使用中firefox与ie不兼容之一
- jQuery上下键选表格行(兼容IE和Firefox)
- jquery 通过flash多文件上传 实现IE和firefox兼容 java版