页面嵌套微博信息,并且自主修改样式显示
<script type="text/javascript"> $(function () { // weibo wb_show($('#weibobox #box '), function () { var as_wb = new autoscroll({ count: $('#weibobox #box > li').size(), speed: 7000, btns: $('#weibobox #box '), pre: $('#btn_left'), next: $('#btn_right') }); as_wb.go = function (index) { if (as_wb.running) return (false); as_wb.running = true; if (index == 0 && as_wb.old != 1) { //$('#weibobox .box').fadeOut(); } $('#weibobox #box ').animate({ 'top': (-index * 140) + 'px' }, 300, function () { as_wb.running = false; }).fadeIn(); return (false); }; $('#btn_left').click(function () { as_wb.pre(); return (false); }); $('#btn_right').click(function () { as_wb.next(); return (false); }); as_wb.index(0); as_wb.start(); if (location.href.indexOf("?xyz=") < 0) { location.href = location.href + "?xyz=" + Math.random(); } }); }); function wb_show(box, callback) { var _this = $(this); var _box = box; var _url = "../../../../MailOnline/WBAjax.aspx"; var _callback = callback; $.ajax({ url: _url, type: 'GET', success: function (data) { var wb_data = $(data); var msg = wb_data.find('.weiboShow_mainFeed_listContent'); var detailName = wb_data.find('.weiboShow_developer_detail').html(); var detailNameDt = wb_data.find('dt').html(); var index = 0; msg.each(function () { var text = $(this).find('.weiboShow_mainFeed_listContent_txt').html().substring(0, 70); var img = $(this).find('.weiboShow_mainFeed_listContent_picshow').html(); var item = '<li>'; item += img ? '<dt><div id="dv_img_' + index++ + '" name="dv_img" style="height:125px;">' + img + '</div></dt>' : ''; item += img ? '<dd class="bt">' + detailNameDt + '</dd>' : '<dd class="bt" style="float:none;padding-left:20px">' + detailNameDt + '</dd>'; item += img ? '<dd class="zw">' + text + '...</dd></li>' : '<dd class="zw" style="padding-left:20px">' + text + '...</dd></li>'; $(item).appendTo(_box); dv_imgWidth(index); }); _callback(); } }); } function dv_imgWidth(index) { var img_left = document.getElementById("dv_img_" + (index - 1)); if (img_left != null) { var img_list = img_left.getElementsByTagName("img"); for (var i = 0; i < img_list.length; i++) { if (img_list[i].width > 70) { img_list[i].width = 70; } if (img_list[i].height < 100) { img_list[i].style.marginTop = "30px" } }} } </script> <div style="margin-top:3px;padding-left:0px;clear:both "> <div class="weibobox" id="weibobox" style="position: absolute; display: block; overflow: hidden;"> <ul id="box" style="position: absolute; display: block; overflow: hidden; width: 284px"> </ul> <div class="bluebox"> <span class="jts"><a href="#" id="btn_left"></a></span><span class="sxwz f14 fstrong fblue"> <span>官</span><br /> <span>方</span><br /> <span>微</span><br /> <span>博</span></span> <span class="jtx"><a href="#" id="btn_right"></a></span> </div> </div> </div> </div>
Ajax调取页面代码(只有后台):
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Net; using System.IO; namespace Beyondbit.CMS.WebSite.UI.MailOnline { public partial class WBAjax : System.Web.UI.Page { private static string html = ""; private static DateTime time = DateTime.Now; protected void Page_Load(object sender, EventArgs e) { html = GetHttpWebRequest("http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=550&fansRow=2&ptype=1&speed=0&skin=1&isTitle=0&noborder=0&isWeibo=1&isFans=0&uid=2922998432&verifier=5375064e&dpc=1"); Response.Write(html); } private string GetHttpWebRequest(string url) { Uri uri = new Uri(url); HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(uri); myReq.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705"; myReq.Accept = "*/*"; myReq.KeepAlive = true; myReq.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5"); HttpWebResponse result = (HttpWebResponse)myReq.GetResponse(); Stream receviceStream = result.GetResponseStream(); StreamReader readerOfStream = new StreamReader(receviceStream, System.Text.Encoding.GetEncoding("utf-8")); string strHTML = readerOfStream.ReadToEnd(); readerOfStream.Close(); receviceStream.Close(); result.Close(); return strHTML; } } }

浙公网安备 33010602011771号