天气预报插件更改官方代码实现完全自定义的方法
天气预报官方提供的接口,只能让背景透明,却不能更改文字的颜色。下面给出具体解决方案 折叠 展开 XML/HTML Code 复制内容到剪贴板 !DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//ENhttp://www.
天气预报官方提供的接口,只能让背景透明,却不能更改文字的颜色。下面给出具体解决方案
把上面的代码放到服务器,
注意这段代码,主要是抓取天气预报官网数据,解决跨域的问题
tq_code.php具体代码如下:
这就可以完全修改页面样式实现自定义了,具体引用代码:
转载请注明出处:http://www.1sohu.com/newsHtm/95/n_16895.shtml
折叠XML/HTML Code复制内容到剪贴板
- <!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" />
- <style type="text/css">
- * {margin: 0;padding: 0;list-style:none;font-weight:normal;line-height:180%; }img {border:0;}body {font-family: Verdana, Arial, Helvetica, sans-serif;background-color:transparent;color:#000;font-size:12px;text-align:center;}a {color:#000;text-decoration:none;}a:hover {color:#FF6600;text-decoration:underline;}em {font-style:normal;}strong {}a strong {}select {height:20px;line-height:20px;}ul.row {clear:both;}ul.row li {float:left;margin:0 4px;}ul.row li a {display:inline;height:22px;line-height:22px;}.more a {}ul.col li {margin:4px auto;text-align:center;font-size:14px;font-weight:bold;}ul.col li #city {font-weight:bold;margin-left:10px;}ul.col li a {font-size:14px;font-weight:bold;}ul.col .small {padding-top:6px;}ul.col .small a {font-size:12px;}ul.col .line {padding:10px;border-bottom:1px dashed #ddd;}dl {clear:both;margin:0 auto;}dl dt {float:left;height:65px;margin-right:10px;}dl dt strong {display:block;margin-top:5px;*margin-top:10px;_margin-top:15px;}dl dt a {}dl dd {margin-left:5px;text-align:left;height:18px;line-height:18px;padding:0;margin:0;}dl .title {margin-bottom:4px;_margin-bottom:-4px;}dl .title #city {font-size:14px;font-weight:bold;}#cj {clear:both;}#left {float:left;text-align:center;}#left h3 { margin-bottom:4px; }#left h3 #city {font-size:14px;font-weight:bold;}#cj h4 {font-size:12px;margin-bottom:5px;}#right {margin-left:10px;text-align:left;float:left;}#cjbg {background:url(/img/bg.gif) left bottom repeat-x;height:90px;padding:10px;}#cjbg .line {border-left:1px solid #ddd;padding-left:8px;}#cjbg h4 {font-size:12px;}#right h3 #city {font-size:14px;margin-right:10px;font-weight:bold;margin-bottom:4px;}ul.new { background-color:transparent; height:28px; line-height:28px; }ul.new li a img { margin-top:4px; } ul.new li a em {font-weight:bold;color:#fff;line-height:28px;}ul.new li a:hover {text-decoration:none;color:#000;}ul.new li a:hover em {color:#000;}#eNew {text-align:left;margin:0 auto;width:150px;height:180px;}#eNew h1 {font-size:20px;margin-bottom:0;}#eNew h2 a em { font-size:14px; font-weight:normal; }#eNew h4 {background:url(/img/w.gif) left top no-repeat;height:43px;line-height:43px;text-indent:1em;width:150px;}#eNew h4 a em {line-height:43px;font-size:18px;font-weight:blod;}#eNew p {font-size:12px;}.blue { text-align:right; }.blue li a { color:#0070C0; }ul.blue li{ float:right; }img, div { behavior: url(iepngfix.htc) }
- </style>
- </head>
- <body>
- <ul class="row">
- <li><a id="url1" href="" target="_blank"><em id="city"></em></a></li>
- <li><a id="url2" href="" target="_blank"><img id="small1" src="" alt="" width="20" height="20" /></a></li>
- <li><a id="url3" href="" target="_blank"><em id="temp1"></em></a></li>
- <li><a id="url4" href="" target="_blank"><em id="wind1"></em></a></li>
- </ul>
- <script type="text/javascript">
- var xmlhttp=null;
- var jsonobj;
- var rs="http://61.4.185.48:81/g/";
- var cookie_info= getCookie('newcity1');
- var id1;
- var ids="url1,url2,url3,url4";
- var url=window.location.href;
- var start=url.indexOf("id");
- var end=url.indexOf("T");
- var setURL=function(ids, url)
- {var nodes=ids;if(typeof nodes=="string"){nodesnodes=nodes.split(",");}
- for( var i=0; i<nodes.length; i++){if(document.getElementById(nodes[i])){document.getElementById(nodes[i]).href=url;}}}
- function setCookie(name, value)
- { var argv = setCookie.arguments;
- var argc = setCookie.arguments.length;
- var expires = (argc > 2) ? argv[2] : null;
- if(expires!=null)
- { var LargeExpDate = new Date (); LargeExpDate.setTime(LargeExpDate.getTime() + (expires*365*24*60*60*1000*10));}
- document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString())); }
- function getCookie(Name)
- {var search = Name + "=" ;
- if(document.cookie.length > 0)
- {offset = document.cookie.indexOf(search)
- if(offset != -1)
- {offset += search.length;
- end = document.cookie.indexOf(";", offset);
- if(end == -1) end = document.cookie.length;
- return unescape(document.cookie.substring(offset, end));}
- else return "";} }
- function createXMLHTTPRequext()
- {
- if (window.XMLHttpRequest)
- {xmlhttp = new XMLHttpRequest(); }
- else if (window.ActiveXObject)
- {xmlhttp =new ActiveXObject("Msxml2.XMLHTTP") ;
- if (! xmlhttp )
- {xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }}}
- function HandleStateChange()
- {if (xmlhttp.readyState == 4)
- {var jsontext =xmlhttp.responseText;
- var func = new Function("return " + jsontext);
- jsonobj = func();} }
- function PostOrder(xmldoc)
- {createXMLHTTPRequext();
- // try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } catch (e) { alert("Permission UniversalBrowserRead denied."); }
- xmlhttp.open("GET", xmldoc,false);
- xmlhttp.onreadystatechange= HandleStateChange;
- xmlhttp.send(null); }
- function returndata(id){var datastr1;
- if(id==""){str="101010100";
- datastr1='/tq/tq_code.php?cd='+str;}else{datastr1='/tq/tq_code.php?cd='+id;}
- PostOrder(datastr1);
- HandleStateChange();
- var parseData=new Object();
- with(jsonobj.weatherinfo){parseData={city: {innerHTML: city},
- temp1: {innerHTML: temp1},
- wind1: {innerHTML: wind1},
- index_d: {innerHTML: index_d},
- index_uv: {innerHTML: index_uv},
- small1: {src:"http://m.weather.com.cn/img/c"+(img2==99?img1:img2)+".gif",
- title: "中国天气网今日天气指数 紫外线指数:"+index_uv+"。"+"穿衣指数:"+index_d},
- small2: {src:"http://m.weather.com.cn/img/c"+img2+".gif",
- title: "中国天气网今日天气指数 紫外线指数:"+index_uv+"。"+"穿衣指数:"+index_d}}}
- for( var m in parseData){var node=document.getElementById(m);
- var sets=parseData[m];
- if(node){for( var prop in sets ){node[prop]=sets[prop];}}}}
- if(start!=-1){var first=start+parseInt(3);
- call=url.substring(first,end);
- returndata(call);
- setURL(ids,"http://www.weather.com.cn/weather/"+call+".shtml");}
- else{if(!cookie_info)
- {var js = document.createElement("script");
- js.setAttribute("type", "text/javascript");
- js.setAttribute("src",rs);
- document.body.insertBefore(js, null);
- function id_callback()
- {
- std = id;
- if(typeof(id)=="undefined")
- {id1="101010100";
- setURL(ids,"http://www.weather.com.cn/weather/"+id1+".shtml");
- returndata(id1);}
- else
- {id1=std;
- time=new Date();
- time.setTime(time.getTime()+365*24*60*60*1000*10);
- date=time.toGMTString();
- document.cookie = "newcity1=" + escape(std)+ ";expires="+date;
- setURL(ids,"http://www.weather.com.cn/weather/"+id1+".shtml");
- returndata(std);}}}else{id1=cookie_info;
- setURL(ids,"http://www.weather.com.cn/weather/"+id1+".shtml");
- returndata(id1);}}var vjAcc="";var wrUrl="http://c.wrating.com/";var wrSv=0;function vjTrack(C){var B=vjValidateTrack();if(B===false){return }var A=wrUrl+"a.gif"+vjGetTrackImgUrl(C);document.write('<div style="display:none"><img src="'+A+'" id="wrTagImage" width="1" height="1"/></div>');vjSurveyCheck()}function vjEventTrack(D){var C=vjValidateTrack();if(C===false){return }var B=wrUrl+"a.gif"+vjGetTrackImgUrl(D);var A=new Image();A.src=B;A.onload=function(){}}function vjValidateTrack(){if(document.location.protocol=="file:"){return false}if(vjAcc==""){return false}else{if(wrUrl.substr(wrUrl.length-1,1)!="/"){wrUrl+="/"}}return true}function vjGetTrackImgUrl(S){var M=0;var N="expires=Fri, 1 Jan 2038 00:00:00 GMT;";var T=document.location;var P=document.referrer.toString();var D;var H=vjGetDomainFromUrl(T);var K;var V;var Y="";var L=vjFlash();var G="";var Z="";var J="";var O=navigator.appName+" "+navigator.appVersion;var F=new Date();var X=F.getTimezoneOffset()/-60;var A=0;var U="";var R="";if(typeof (H[1])!="undefined"){V=H[1]}else{if(typeof (H[0])!="undefined"){V=H[0]}}if(P!=""){Y=vjGetKeyword(P)}else{if((O.indexOf("MSIE")>=0)&&(parseInt(O.substr(O.indexOf("MSIE")+5),4)>=5)&&(O.indexOf("Mac")==-1)&&(navigator.userAgent.indexOf("Opera")==-1)){try{document.documentElement.addBehavior("#default#homePage");if(document.documentElement.isHomePage(location.href)){P="ishomepage"}}catch(W){}}}if(navigator.cookieEnabled){M=1}if(self.screen){G=screen.width+"x"+screen.height+"x"+screen.colorDepth}else{if(self.java){var Q=java.awt.Toolkit.getDefaultToolkit().getScreenSize();G=Q.width+"x"+Q.height+"x0"}}if(navigator.language){Z=navigator.language.toLowerCase()}else{if(navigator.browserLanguage){Z=navigator.browserLanguage.toLowerCase()}else{Z="-"}}if(navigator.javaEnabled()){A=1}if(M==1){D=document.cookie;if(D.indexOf("vjuidsvjuids=")<0){K=vjVisitorID();document.cookie="vjuids="+escape(K)+";"+N+";domain="+V+";path=/;"}else{K=vjGetCookie("vjuids")}if(D.indexOf("vjlast=")<0){U="30";var E=vjGetTimestamp(F.getTime()).toString();R=E+"."+E+".30"}else{var a=vjGetCookie("vjlast");var C=a.split(".");var B="";if(typeof (C[0])!="undefined"){R=C[0].toString()}else{R=vjGetTimestamp(F.getTime()).toString()}if(typeof (C[1])!="undefined"){var I=new Date(parseInt(C[1])*1000);if(I.toDateString()!=F.toDateString()){R+="."+vjGetTimestamp(F.getTime()).toString();if(parseInt(vjGetTimestamp(F.getTime())-parseInt(C[1]))/86400>30){U="2"}else{U="1"}if(typeof (C[2])!="undefined"){U+=C[2].substr(0,1)}else{U+="0"}}else{R+="."+C[1].toString();if(typeof (C[2])!="undefined"){U+=C[2]}else{U="10"}}}else{R+="."+vjGetTimestamp(F.getTime()).toString();if(typeof (C[2])!="undefined"){U+=C[2]}else{U="10"}}R+="."+U}document.cookie="vjlast="+R+";"+N+";domain="+V+";path=/;"}J="?a="+F.getTime().toString(16)+"&t=&i="+escape(K);J+="&b="+escape(T)+"&c="+vjAcc;J+="&s="+G+"&l="+Z;J+="&z="+X+"&j="+A+"&f="+escape(L);if(P!=""){J+="&r="+escape(P)+"&kw="+Y}J+="&ut="+U+"&n=";if(typeof (S)=="undefined"){J+="&js="}else{J+="&js="+escape(S)}J+="&ck="+M;return J}function vjGetTimestamp(A){return Math.round(A/1000)}function vjGetKeyword(C){var A=[["baidu","wd"],["baidu","q1"],["google","q"],["google","as_q"],["yahoo","p"],["msn","q"],["live","q"],["sogou","query"],["youdao","q"],["soso","w"],["zhongsou","w"],["zhongsou","w1"]];var B=vjGetDomainFromUrl(C.toString().toLowerCase());var D=-1;var E="";if(typeof (B[0])=="undefined"){return""}for(i=0;i<A.length;i++){if(B[0].indexOf("."+A[i][0]+".")>=0){D=-1;D=C.indexOf("&"+A[i][1]+"=");if(D<0){D=C.indexOf("?"+A[i][1]+"=")}if(D>=0){E=C.substr(D+A[i][1].length+2,C.length-(D+A[i][1].length+2));D=E.indexOf("&");if(D>=0){EE=E.substr(0,D)}if(E==""){return""}else{return A[i][0]+"|"+E}}}}return""}function vjGetDomainFromUrl(E){if(E==""){return false}EE=E.toString().toLowerCase();var F=[];var C=E.indexOf("//")+2;var B=E.substr(C,E.length-C);var A=B.indexOf("/");if(A>=0){F[0]=B.substr(0,A)}else{F[0]=B}var D=F[0].match(/[^.]+\.(com.cn|net.cn|gov.cn|cn|com|net|org|gov|cc|biz|info)+$/);if(D){if(typeof (D[0])!="undefined"){F[1]=D[0]}}return F}function vjVisitorID(){var A=vjHash(document.location+document.cookie+document.referrer).toString(16);var B=new Date();return A+"."+B.getTime().toString(16)+"."+Math.random().toString(16)}function vjHash(C){if(!C||C==""){return 0}var B=0;for(var A=C.length-1;A>=0;A--){var D=parseInt(C.charCodeAt(A));B=(B<<5)+B+D}return B}function vjGetCookie(D){var B=D+"=";var F=B.length;var A=document.cookie.length;var E=0;while(E<A){var C=E+F;if(document.cookie.substring(E,C)==B){return vjGetCookieVal(C)}E=document.cookie.indexOf(" ",E)+1;if(E==1){break}}return null}function vjGetCookieVal(B){var A=document.cookie.indexOf(";",B);if(A==-1){A=document.cookie.length}return unescape(document.cookie.substring(B,A))}function vjFlash(){var _flashVer="-";var _navigator=navigator;if(_navigator.plugins&&_navigator.plugins.length){for(var ii=0;ii<_navigator.plugins.length;ii++){if(_navigator.plugins[ii].name.indexOf("Shockwave Flash")!=-1){_flashVer=_navigator.plugins[ii].description.split("Shockwave Flash ")[1];break}}}else{if(window.ActiveXObject){for(var ii=10;ii>=2;ii--){try{var fl=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+ii+"');");if(fl){_flashVer=ii+".0";break}}catch(e){}}}}return _flashVer}function vjSurveyCheck(){if(wrSv<=0){return }var C=new Date();var A=C.getTime();var D=Math.random(A);if(D<=parseFloat(1/wrSv)){var B=document.createElement("script");B.type="text/javascript";B.id="wratingSuevey";B.src="http://tongji.wrating.com/survey/check.php?c="+vjAcc;document.getElementsByTagName("head")[0].appendChild(B)}};
- var vjAcc="860010-2151010100";
- var wrUrl="http://c.wrating.com/";
- var wrRandom = 70;
- var now = new Date();
- var seed = now.getTime();
- var randomNumber = Math.random(seed);
- if (randomNumber <= parseFloat(1/wrRandom))
- { vjTrack("");}
- </script>
- <noscript><img src="http://c.wrating.com/a.gif?a=&c=860010-2151010100" width="1" height="1"/></noscript>
- </body>
- </html>
注意这段代码,主要是抓取天气预报官网数据,解决跨域的问题
XML/HTML Code复制内容到剪贴板
- datastr1='/tq/tq_code.php?cd='+str;}else{datastr1='/tq/tq_code.php?cd='+id;}
XML/HTML Code复制内容到剪贴板
- <?php
- $code=intval($_GET['cd']);
- $url="http://m.weather.com.cn/data/".$code.".html";
- $content=file_get_contents($url);
- echo $content;
- ?>
XML/HTML Code复制内容到剪贴板
- <iframe width="165" scrolling="no" height="20" frameborder="0" allowtransparency="" vspace="0" hspace="0" marginheight="0" marginwidth="0" src="http://www.1sohu.com/tq/qixiang.html"></iframe>
转载请注明出处:http://www.1sohu.com/newsHtm/95/n_16895.shtml
精彩图集
精彩文章