Aug
11
右下角,可关闭,检测IP,根据来访地区在框架中打开不同的网页
雪糕先生 2009/08/11
18:00

如何让我们的网页更加人性化,自动化,根据来访者的不同IP来选择我们子框架中的网页呢?
我以右下角可关闭广告代码为例:
首先编写一个JS文件: area_ip.js 内容如下:
根据你的需要修改相应部分,再在你上级网页中加入调用代码:
大功告成!
我以右下角可关闭广告代码为例:
首先编写一个JS文件: area_ip.js 内容如下:
引用
var PClocation = unescape(getCookie('PClocation'));/*存储ip判断的地区字段*/
var area_lmt_tag = 'bj';/*初始化当前城市显示的窗口,没有车市的一律显示北京的;*/
function setCookie(name, value, expires, path, domain, secure){
var expires = new Date();
expires.setTime(expires.getTime() + 24*60*60*1000);
var domain=".pconline.com.cn"
var s = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString(): "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie=s;
}
function getCookie(name){
return unescape(document.cookie.replace(new RegExp(".*(?:^|; )"+name+"=([^;]*).*|.*"),"$1"));
}
function IPCallBack(location){
PClocation = location;
setCookie('PClocation',escape(location));
}
function needJS(fn,src,callback) {
if(typeof callback == 'undefined' || callback == null) callback = function(){};
if(typeof fn != 'undefined' && fn != null && fn != '') return callback();
var status = typeof _needJS_ == 'undefined' ? _needJS_ = {loaded:[],loading:[]} : _needJS_;
for(var i=0; i<status.loaded.length; i++) {
if(status.loaded[i] == src) return callback();
}
function idx(src) { //供后面的代码调用
for(var i=0;i<status.loading.length;i++) if(status.loading[i].src==src) return i;
}
var loading = status.loading[idx(src)];
if(loading != null) {
loading.callbacks.push(callback);
return;
}
status.loading.push(loading = {src:src,callbacks:[callback]});
var js = document.createElement('script');
js.src = src;
js.onload = js.onreadystatechange = function() {
if(typeof js.readyState == 'undefined' || js.readyState == 'loaded' || js.readyState == 'complete') {
status.loaded.push(loading.src);
var callbacks = loading.callbacks;
status.loading.splice(idx(src),1);
for(var i = 0; i < callbacks.length; i++) {
loading.callbacks[i]();
}
}
}
document.getElementsByTagName('head')[0].appendChild(js);
}
//关闭,最小化,最大化
function showDiv(innerCall){
if(document.getElementById('PcPoPmarket')==null)return;
if(Number(getCookie("divStatus"))==1 && !!innerCall){
closeDiv();
}else if (Number(getCookie("divStatus"))==2 && !!innerCall)
{
hideDiv();
}else{
document.getElementById('PcPoPmarket').style.height = 237+'px';
document.getElementById('showvod').style.display = 'none';
document.getElementById('hidevod').style.display = 'block';
}
}
function hideDiv(innerCall){
if(document.getElementById('PcPoPmarket')==null)return;
document.getElementById('PcPoPmarket').style.height = 29 + 'px';
document.getElementById('hidevod').style.display = 'none';
document.getElementById('showvod').style.display = 'block';
if(!innerCall)setCookie("divStatus",2);
}
function closeDiv(innerCall){
if(document.getElementById('PcPoPmarket')==null)return;
document.getElementById('PcPoPmarket').style.display = 'none';
if(!innerCall)setCookie("divStatus",1);
}
document.write("<span id=tmpAreaLmtDiv></span>");
//writeAreaLmtDiv(area_lmt_tag);
function writeAreaLmtDiv() {
if (area_lmt_tag!=null && area_lmt_tag.length > 0){
var s="";
try{
//以下是为了兼容 xhtml1.0 和 html4两种情况 / ie6 ie7 ff 的兼容用hack
if(document.compatMode && document.compatMode != 'BackCompat'){
s+=('<DIV style="z-index:1000;right:0;bottom:0; height:237px;width:350px;overflow:hidden;POSITION:fixed;'+(/MSIE 7/.test(navigator.appVersion)?'':'_position:absolute; _margin-top:expression(document.documentElement.clientHeight-this.style.pixelHeight+document.documentElement.scrollTop);')+'" id="PcPoPmarket" >');
}else {
s+=('<DIV style="z-index:1000;right:0;bottom:0; height:237px;width:350px;overflow:hidden;POSITION:fixed;*position:absolute; *top:expression(eval(document.body.scrollTop)+eval(document.body.clientHeight)-this.style.pixelHeight);" id="PcPoPmarket" >');
}
s+=(' <div style="z-index:1000; POSITION: absolute; width:350px; height:30px; overflow:hidden;"><span style="CURSOR: pointer;float:left;clear:none; width:123px; height:14px; overflow:hidden; margin:10px 5px;"></span><span style="CURSOR: pointer;float:right;clear:none; width:15px; height:14px; margin:6px 5px;" onclick=closeDiv()></span><span style="background-image:url(http://www1.pconline.com.cn/images/lmt/oncity_big.gif);CURSOR: pointer;float:right; width:15px; height:14px; overflow:hidden;clear:none;display:none; margin:9px 1px 0 0; " onclick=showDiv() id="showvod"></span><span style="background-image:url(http://www1.pconline.com.cn/images/lmt/oncity_small.gif);CURSOR: pointer;float:right;overflow:hidden; width:15px; height:14px; clear:none; display:bolck; margin:9px 1px 0 0;" onclick=hideDiv() id="hidevod"></span></div> ');
s+=("<iframe scrolling=no frameborder=0 width=350 height=237 src=http://www.btoss.com/"+area_lmt_tag+"/>-</iframe>");
s+=('</DIV>');
document.getElementById('tmpAreaLmtDiv').innerHTML = s;
setTimeout('hideDiv(true);', 8000);
}catch(err){}
}
showDiv(true);
}
function playLmtAreaWindow(){
if(PClocation.indexOf('广东')>=0 && PClocation.indexOf('深圳')<0 && PClocation.indexOf('惠州')<0 && PClocation.indexOf('东莞')<0){
area_lmt_tag='gz';
}else if(PClocation.indexOf('深圳')>=0 || PClocation.indexOf('惠州')>=0 || PClocation.indexOf('东莞')>=0){
area_lmt_tag='sz';
}else if(PClocation.indexOf('北京')>=0){
area_lmt_tag='bj';
}else if(PClocation.indexOf('上海')>=0){
area_lmt_tag='sh';
}else if(PClocation.indexOf('香港')>=0){
area_lmt_tag='hk';
}else if(PClocation.indexOf('广西')>=0){
area_lmt_tag='gx';
}else if(PClocation.indexOf('重庆')>=0){
area_lmt_tag='cq';
}else if(PClocation.indexOf('湖北')>=0){
area_lmt_tag='wh';
}else if(PClocation.indexOf('山东')>=0){
area_lmt_tag='sd';
}else if(PClocation.indexOf('江苏')>=0){
area_lmt_tag='js';
}else if(PClocation.indexOf('吉林')>=0 || PClocation.indexOf('辽宁')>=0){
area_lmt_tag='ln';
}else if(PClocation.indexOf('福建')>=0){
area_lmt_tag='fj';
}else if(PClocation.indexOf('成都')>=0){
area_lmt_tag='cd';
}else if(PClocation.indexOf('西安')>=0){
area_lmt_tag='xa';
}else if(PClocation.indexOf('湖南')>=0){
area_lmt_tag='hn';
}else if(PClocation.indexOf('江西')>=0){
area_lmt_tag='jx';
}else if(PClocation.indexOf('黑龙江')>=0){
area_lmt_tag='hl'
}else if(PClocation.indexOf('内蒙古')>=0){
area_lmt_tag='nm'
}else if(PClocation.indexOf('台湾')>=0){
area_lmt_tag='tw';
}else if(PClocation.indexOf('浙江')>=0){
area_lmt_tag='zj';
}else if(PClocation.indexOf('河北')>=0){
area_lmt_tag='hb';
}else if(PClocation.indexOf('河南')>=0){
area_lmt_tag='henan';
}else {area_lmt_tag='bj'}
writeAreaLmtDiv();
}
//执行
if(PClocation==null || PClocation.length==0){
needJS(null,'http://whois.pconline.com.cn/jsFunction.jsp',playLmtAreaWindow);
}else{
playLmtAreaWindow();
}
var area_lmt_tag = 'bj';/*初始化当前城市显示的窗口,没有车市的一律显示北京的;*/
function setCookie(name, value, expires, path, domain, secure){
var expires = new Date();
expires.setTime(expires.getTime() + 24*60*60*1000);
var domain=".pconline.com.cn"
var s = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString(): "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie=s;
}
function getCookie(name){
return unescape(document.cookie.replace(new RegExp(".*(?:^|; )"+name+"=([^;]*).*|.*"),"$1"));
}
function IPCallBack(location){
PClocation = location;
setCookie('PClocation',escape(location));
}
function needJS(fn,src,callback) {
if(typeof callback == 'undefined' || callback == null) callback = function(){};
if(typeof fn != 'undefined' && fn != null && fn != '') return callback();
var status = typeof _needJS_ == 'undefined' ? _needJS_ = {loaded:[],loading:[]} : _needJS_;
for(var i=0; i<status.loaded.length; i++) {
if(status.loaded[i] == src) return callback();
}
function idx(src) { //供后面的代码调用
for(var i=0;i<status.loading.length;i++) if(status.loading[i].src==src) return i;
}
var loading = status.loading[idx(src)];
if(loading != null) {
loading.callbacks.push(callback);
return;
}
status.loading.push(loading = {src:src,callbacks:[callback]});
var js = document.createElement('script');
js.src = src;
js.onload = js.onreadystatechange = function() {
if(typeof js.readyState == 'undefined' || js.readyState == 'loaded' || js.readyState == 'complete') {
status.loaded.push(loading.src);
var callbacks = loading.callbacks;
status.loading.splice(idx(src),1);
for(var i = 0; i < callbacks.length; i++) {
loading.callbacks[i]();
}
}
}
document.getElementsByTagName('head')[0].appendChild(js);
}
//关闭,最小化,最大化
function showDiv(innerCall){
if(document.getElementById('PcPoPmarket')==null)return;
if(Number(getCookie("divStatus"))==1 && !!innerCall){
closeDiv();
}else if (Number(getCookie("divStatus"))==2 && !!innerCall)
{
hideDiv();
}else{
document.getElementById('PcPoPmarket').style.height = 237+'px';
document.getElementById('showvod').style.display = 'none';
document.getElementById('hidevod').style.display = 'block';
}
}
function hideDiv(innerCall){
if(document.getElementById('PcPoPmarket')==null)return;
document.getElementById('PcPoPmarket').style.height = 29 + 'px';
document.getElementById('hidevod').style.display = 'none';
document.getElementById('showvod').style.display = 'block';
if(!innerCall)setCookie("divStatus",2);
}
function closeDiv(innerCall){
if(document.getElementById('PcPoPmarket')==null)return;
document.getElementById('PcPoPmarket').style.display = 'none';
if(!innerCall)setCookie("divStatus",1);
}
document.write("<span id=tmpAreaLmtDiv></span>");
//writeAreaLmtDiv(area_lmt_tag);
function writeAreaLmtDiv() {
if (area_lmt_tag!=null && area_lmt_tag.length > 0){
var s="";
try{
//以下是为了兼容 xhtml1.0 和 html4两种情况 / ie6 ie7 ff 的兼容用hack
if(document.compatMode && document.compatMode != 'BackCompat'){
s+=('<DIV style="z-index:1000;right:0;bottom:0; height:237px;width:350px;overflow:hidden;POSITION:fixed;'+(/MSIE 7/.test(navigator.appVersion)?'':'_position:absolute; _margin-top:expression(document.documentElement.clientHeight-this.style.pixelHeight+document.documentElement.scrollTop);')+'" id="PcPoPmarket" >');
}else {
s+=('<DIV style="z-index:1000;right:0;bottom:0; height:237px;width:350px;overflow:hidden;POSITION:fixed;*position:absolute; *top:expression(eval(document.body.scrollTop)+eval(document.body.clientHeight)-this.style.pixelHeight);" id="PcPoPmarket" >');
}
s+=(' <div style="z-index:1000; POSITION: absolute; width:350px; height:30px; overflow:hidden;"><span style="CURSOR: pointer;float:left;clear:none; width:123px; height:14px; overflow:hidden; margin:10px 5px;"></span><span style="CURSOR: pointer;float:right;clear:none; width:15px; height:14px; margin:6px 5px;" onclick=closeDiv()></span><span style="background-image:url(http://www1.pconline.com.cn/images/lmt/oncity_big.gif);CURSOR: pointer;float:right; width:15px; height:14px; overflow:hidden;clear:none;display:none; margin:9px 1px 0 0; " onclick=showDiv() id="showvod"></span><span style="background-image:url(http://www1.pconline.com.cn/images/lmt/oncity_small.gif);CURSOR: pointer;float:right;overflow:hidden; width:15px; height:14px; clear:none; display:bolck; margin:9px 1px 0 0;" onclick=hideDiv() id="hidevod"></span></div> ');
s+=("<iframe scrolling=no frameborder=0 width=350 height=237 src=http://www.btoss.com/"+area_lmt_tag+"/>-</iframe>");
s+=('</DIV>');
document.getElementById('tmpAreaLmtDiv').innerHTML = s;
setTimeout('hideDiv(true);', 8000);
}catch(err){}
}
showDiv(true);
}
function playLmtAreaWindow(){
if(PClocation.indexOf('广东')>=0 && PClocation.indexOf('深圳')<0 && PClocation.indexOf('惠州')<0 && PClocation.indexOf('东莞')<0){
area_lmt_tag='gz';
}else if(PClocation.indexOf('深圳')>=0 || PClocation.indexOf('惠州')>=0 || PClocation.indexOf('东莞')>=0){
area_lmt_tag='sz';
}else if(PClocation.indexOf('北京')>=0){
area_lmt_tag='bj';
}else if(PClocation.indexOf('上海')>=0){
area_lmt_tag='sh';
}else if(PClocation.indexOf('香港')>=0){
area_lmt_tag='hk';
}else if(PClocation.indexOf('广西')>=0){
area_lmt_tag='gx';
}else if(PClocation.indexOf('重庆')>=0){
area_lmt_tag='cq';
}else if(PClocation.indexOf('湖北')>=0){
area_lmt_tag='wh';
}else if(PClocation.indexOf('山东')>=0){
area_lmt_tag='sd';
}else if(PClocation.indexOf('江苏')>=0){
area_lmt_tag='js';
}else if(PClocation.indexOf('吉林')>=0 || PClocation.indexOf('辽宁')>=0){
area_lmt_tag='ln';
}else if(PClocation.indexOf('福建')>=0){
area_lmt_tag='fj';
}else if(PClocation.indexOf('成都')>=0){
area_lmt_tag='cd';
}else if(PClocation.indexOf('西安')>=0){
area_lmt_tag='xa';
}else if(PClocation.indexOf('湖南')>=0){
area_lmt_tag='hn';
}else if(PClocation.indexOf('江西')>=0){
area_lmt_tag='jx';
}else if(PClocation.indexOf('黑龙江')>=0){
area_lmt_tag='hl'
}else if(PClocation.indexOf('内蒙古')>=0){
area_lmt_tag='nm'
}else if(PClocation.indexOf('台湾')>=0){
area_lmt_tag='tw';
}else if(PClocation.indexOf('浙江')>=0){
area_lmt_tag='zj';
}else if(PClocation.indexOf('河北')>=0){
area_lmt_tag='hb';
}else if(PClocation.indexOf('河南')>=0){
area_lmt_tag='henan';
}else {area_lmt_tag='bj'}
writeAreaLmtDiv();
}
//执行
if(PClocation==null || PClocation.length==0){
needJS(null,'http://whois.pconline.com.cn/jsFunction.jsp',playLmtAreaWindow);
}else{
playLmtAreaWindow();
}
根据你的需要修改相应部分,再在你上级网页中加入调用代码:
引用
<script type="text/javascript" src="http://btoss.com/images/area_ip.js"></script>
大功告成!
分类
热门文章
- [46876]五种方法安装Windows...
- [32603]您可能需要与该网络的 in...
- [16663]2012东埔英歌舞
- [15529]开机自动检测网络状态运行程...
- [15512]APMServ一键快速搭建...
- [14571]EvaPhone - 无需...
- [14331]各种BIOS的设置细解
- [13848]Google提供的免费天气...
- [13395]双路由器上网的连接和设置方...
- [12882]雪糕乐园小游戏集2.04版...