Add the latest article List for Donews blog using XMLHTTP technology

Source: Internet
Author: User
Tags add return window domain name
The majority of XML Donews blog templates do not display the latest article List of features, the following is the use of XMLHTTP technology to achieve this function of the idea and code, the effect of the left side of the "latest article" column. Because Donews blog and discuz Forum, the different templates are each, can not give a unified variable name (HTML tag ID value), so need to be in the code based on CSS modified to produce the appropriate effect.

Ideas and technical background

The idea is very simple, directly with XMLHTTP Read Blog RSS file, take out the latest article inserted in advance prepared HTML tag can.

XMLHTTP is the technology that Microsoft invented in the last century for its own web apps, which the big speakers gave a new name, Ajax, to compliment Google on several web apps, but threw Microsoft aside. As Microsoft, Firefox and Opera integrate XMLHTTP into their respective browsers, Web developers do not need to let users download ActiveX, simply call them with a favorite Web script, and Ajax effects begin to spread.

Raw Code

<ul class= "list" id= "My_last_post" ></ul><ul class= "list" ><li>
<script type= "Text/javascript" ><!--
var xmlhttp = false;
function Load_rss ()
{
XMLHTTP = false;
if (window. XMLHttpRequest)
{
XMLHTTP = new XMLHttpRequest ();
if (Xmlhttp.overridemimetype)
{
Xmlhttp.overridemimetype (' Text/xml ');
}
}
else if (window. ActiveXObject)
{
Try
{
XMLHTTP = new ActiveXObject ("Msxml2.xmlhttp");
}
catch (E)
{
Try
{
XMLHTTP = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
}
}
}
if (!xmlhttp)
{
Return
}
Xmlhttp.onreadystatechange = Proc_rss;
Xmlhttp.open (' Get ', '/concorde/rss.aspx ', true);
Xmlhttp.send (NULL);
}

function Proc_rss ()
{
if (xmlhttp.readystate = 4)
{
if (Xmlhttp.status = 200)
{
var items = xmlhttp.responseXML.getElementsByTagName (' item ');
var L = 6;
if (Items.length < 6)
{
L = items.length;
}
var html = ';
for (var i = 0; i < L; i++)
{
html = html + get_item (items, i);
}
var obj = document.getElementById (' my_last_post ');
if (obj)
{
obj.innerhtml = html;
}
}
}
}

function get_item (items, IDS)
{
var link = items[id].getelementsbytagname (' link '). Item (0). Firstchild.nodevalue;
var title = Items[id].getelementsbytagname (' title '). Item (0). Firstchild.nodevalue;
var item = ' <li class= ' listitem ' ><a href= ' + link + ' > ' + title + ' </a></li> ';
return item;
}
Load_rss ();
File://-->
</script>

The second line of code has an open <ul class= "list" ><li>, which is used to close the following code (written in the template of the Donews blog); '/concorde/rss.aspx ' in the code You need to modify the RSS feed for yourself or someone else (but you cannot use XML other than the blog.donews.com domain name, such as Feedbunrer); finally put the code in the "options» Configuration» Bulletin" where it fits. To decorate the display, you may need to match the appropriate CSS code. It is also recommended that you add:. Listitem{word-wrap:break-word;overflow:hidden in custom CSS styles This prevents comments in IE to support large pages, in Firefox is hidden overflow text.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.