About This Code
Brief Description:
Building Site Favorites with an XML Super Cookie
Contributor:
Andrew Jones
Last Modified:
17 Jun 2002
OpenNTF Disclaimer
All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.
Code / Description
function AddFavorite(sURL, sTitle) {
// Load the favorites file
siteFavorites.load("favorites")
// Access the document
var oXMLDoc=siteFavorites.XMLDocument;
// Create three elements
var oNode=oXMLDoc.createNode(1,"SITEINFO", "");
var oURLNode=oXMLDoc.createNode(1,"URL", "");
var oTitleNode=oXMLDoc.createNode(1,"TITLE", "");
// Set the text of the URL and Title
oURLNode.text=sURL;
oTitleNode.text = sTitle
// Parent the URL and Title to the SITEINFO element
oNode.insertBefore(oURLNode,null)
oNode.insertBefore(oTitleNode,null)
// Add the new SITEINFO block to the favorites XML file
oXMLDoc.documentElement.insertBefore(oNode, null);
// Save the new file to disk
siteFavorites.save("favorites")
}
function ListFavorites() {
// Open a new window and display the header
var wList = window.open("","fav","width=300,height=200,top=0,left=0,scrollbars=yes")
wList.document.open()
wList.document.write("<TITLE>SiteExperts.com Favorite List</TITLE>")
wList.document.write("<BASE TARGET=\"_blank\">")
// Load the file
siteFavorites.load("favorites")
// Get the root node
var oXMLDoc = siteFavorites.XMLDocument.documentElement
// Walk through each SITEINFO block
for (var i=0;i<oXMLDoc.childNodes.length;i++) {
// Output the URL and text as a hyperlink
with (wList.document) {
write("<A HREF=\"" + oXMLDoc.childNodes[i].childNodes[0].text + "\">")
write(oXMLDoc.childNodes[i].childNodes[1].text)
write("</A><BR>")
}
}
wList.document.close()
}
Usage / Example