js对联广告代码,兼容性高

var browser = { ie6: function () { return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined)) }, getWindow: function () { var myHeight = 0; var myWidth = 0; if (typeof (window.innerWidth) == ‘number‘) { myHeight = window.innerHeight; myWidth = window.innerWidth } else if (document.documentElement) { myHeight = document.documentElement.clientHeight; myWidth = document.documentElement.clientWidth } else if (document.body) { myHeight = document.body.clientHeight; myWidth = document.body.clientWidth } return { ‘height‘: myHeight, ‘width‘: myWidth} }, getScroll: function () { var myHeight = 0; var myWidth = 0; if (typeof (window.pageYOffset) == ‘number‘) { myHeight = window.pageYOffset; myWidth = window.pageXOffset } else if (document.documentElement) { myHeight = document.documentElement.scrollTop; myWidth = document.documentElement.scrollLeft } else if (document.body) { myHeight = document.body.scrollTop; myWidth = document.body.scrollLeft } return { ‘height‘: myHeight, ‘width‘: myWidth} }, getDocWidth: function (D) { if (!D) var D = document; return Math.max(Math.max(D.body.scrollWidth, D.documentElement.scrollWidth), Math.max(D.body.offsetWidth, D.documentElement.offsetWidth), Math.max(D.body.clientWidth, D.documentElement.clientWidth)) }, getDocHeight: function (D) { if (!D) var D = document; return Math.max(Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight)) } }; var dom = { ID: function (id) { var type = typeof (id); if (type == ‘object‘) return id; if (type == ‘string‘) return document.getElementById(id); return null }, insertHtml: function (html) { var frag = document.createDocumentFragment(); var div = document.createElement("div"); div.innerHTML = html; for (var i = 0, ii = div.childNodes.length; i < ii; i++) { frag.appendChild(div.childNodes[i]) } document.body.insertBefore(frag, document.body.firstChild) } }; var myEvent = { add: function (element, type, handler) { var ele = dom.ID(element); if (!ele) return; if (ele.addEventListener) ele.addEventListener(type, handler, false); else if (ele.attachEvent) ele.attachEvent("on" + type, handler); else ele["on" + type] = handler }, remove: function (element, type, handler) { var ele = dom.ID(element); if (!ele) return; if (ele.removeEventListener) ele.removeEventListener(type, handler, false); else if (ele.detachEvent) ele.detachEvent("on" + type, handler); else ele["on" + type] = null } }; var position = { rightCenter: function (id) { var id = dom.ID(id); var ie6 = browser.ie6(); var win = browser.getWindow(); var ele = { ‘height‘: id.clientHeight, ‘width‘: id.clientWidth }; if (ie6) { var scrollBar = browser.getScroll() } else { var scrollBar = { ‘height‘: 0, ‘width‘: 0 }; id.style.position = ‘fixed‘ } ele.top = parseInt((win.height - ele.height) / 2 + scrollBar.height); id.style.top = ele.top + ‘px‘; id.style.right = ‘3px‘ }, floatRightCenter: function (id) { position.rightCenter(id); var fun = function () { position.rightCenter(id) }; if (browser.ie6()) { myEvent.add(window, ‘scroll‘, fun); myEvent.add(window, ‘resize‘, fun) } else { myEvent.add(window, ‘resize‘, fun) } }, leftCenter: function (id) { var id = dom.ID(id); var ie6 = browser.ie6(); var win = browser.getWindow(); var ele = { ‘height‘: id.clientHeight, ‘width‘: id.clientWidth }; if (ie6) { var scrollBar = browser.getScroll() } else { var scrollBar = { ‘height‘: 0, ‘width‘: 0 }; id.style.position = ‘fixed‘ } ele.top = parseInt((win.height - ele.height) / 2 + scrollBar.height); id.style.top = ele.top + ‘px‘; id.style.left = ‘3px‘ }, floatLeftCenter: function (id) { position.leftCenter(id); var fun = function () { position.leftCenter(id) }; if (browser.ie6()) { myEvent.add(window, ‘scroll‘, fun); myEvent.add(window, ‘resize‘, fun) } else { myEvent.add(window, ‘resize‘, fun) } } };

function ad_left() {
    var html;
    html = ‘<div id="ad_left" style="position:absolute;width:100px;height:300px;z-index:10001"><a style="position:absolute;top:-15px;left:0;" href="javascript:void(0);" onclick="document.getElementById(\‘ad_left\‘).style.display=\‘none\‘">关闭</a><a href="http://www.xiaotouchengxu.com/" target=_blank><img src="http://www.xiaotouchengxu.com/ad/x1.gif" width="100" height="300" /></a></div>‘;
    dom.insertHtml(html); position.floatLeftCenter(‘ad_left‘);
}
function ad_right() {
    var html;
    html = ‘<div id="ad_right" style="position:absolute;width:100px;height:300px;z-index:10001"><a style="position:absolute;top:-15px;right:0;" href="javascript:void(0);" onclick="document.getElementById(\‘ad_right\‘).style.display=\‘none\‘">关闭</a><a href="http://www.xiaotouchengxu.com/" target=_blank><img src="http://www.xiaotouchengxu.com/ad/x1.gif" width="100" height="300" /></a></div>‘;
    dom.insertHtml(html); position.floatRightCenter(‘ad_right‘);
}
myEvent.add(window, ‘load‘, ad_left);
myEvent.add(window, ‘load‘, ad_right);
时间: 2024-11-05 06:12:05

js对联广告代码,兼容性高的相关文章

可关闭与展开的对联广告代码

<!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-

蓝色经典的对联广告代码

<html><head><title>蓝色经典的对联广告代码</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body><table><tr><td height="1000"></tr></t

带关闭按钮的跟随窗口移动对联广告代码

http://www.xuecss3.com/qttx-25-2991-1.html <!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"> <

JS漂浮广告代码

<html><head><title>漂浮广告</title><body><div id="codefans_net" style="position:absolute"><!--链接地址--><a href="#" target="_blank"><!--图片地址--><img src="/images

JavaScript浮动广告代码,容纯DIV/CSS对联漂浮广告代码,兼容性非常好的js右下角与漂浮广告代码

基于JavaScript代码实现随机漂浮图片广告,javascript图片广告 在网上有很多这样的代码,不过未必符合W3C标准,因为在头部加上<!DOCTYPE html>类似标签之后,漂浮效果就会失效,下面分享一个符合标准的漂浮代码,使需要的朋友免去大量改造代码的繁琐. 代码一: 代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name

JS写出登陆遮罩层+浮动对联广告

用JS写出 遮罩层登陆框 和 对联广告 并自动跟随滚动条 滚动 保持让用户一直可以看到 好了,天色已晚废话不多说,代码特别详细 有注释,请看代码. ================> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xml

JS使用cookie实现只出现一次的广告代码效果

我们上网经常会遇到第一次需要登录而之后不用再登录的网站的情况,其实是运用了Cookie 存储 web 页面的用户信息,Cookie 以名/值对形式存储,当浏览器从服务器上请求 web 页面时, 属于该页面的 cookie 会被添加到该请求中.服务端通过这种方式来获取用户的信息l. 今天的这个效果:第一次打开网页弹出一个广告框(js实现卷帘效果),关闭广告代码或刷新页面之后就不会再出现.由于往电脑里写cookie信息是服务器行为,只有访问网站,服务器才会向电脑里写cookie信息,由于现在只是普通

我们这里有仿百度联盟对联广告实现代码

仿百度联盟对联广告源代码展示,主要使用现代浏览器都支持的position:fixed属性,并专门针对ie6做了最大限度的兼容性处理 <style type="text/css"> 02 *{margin:0;padding:0;} 03 body{height:2000px;} 04 .floatAd{width:124px;height:299px; text-align:center; position:fixed;margin-left:0;top:109px; _p

Js可点击展开关闭的广告代码

<!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><title>网页上可点击展开.关闭的左侧广告代码</t