Saturday, May 30, 2009

Save As Word Document Script

The following JS code will save the inner text of an element like ‹Div id="Save"›, the server must have Microsoft word installed on it and it works only on IE.

function SaveAsWord()
{
var sp = document.getElementById("Save");
var docApp = new ActiveXObject("Word.Application");
var doc = new ActiveXObject("Word.Document");
doc.Application.Visible=false;
doc.Content=sp.innerText;
// Show Save Dialog
doc.Save()
doc.Application.Quit();
}

Add To Favorites Script

function AddToFavorites()
{
var url = document.location.href;

if (window.sidebar)
{
// Mozilla Firefox
window.sidebar.addPanel(document.title, url ,"");
}
else if( window.external )
{
// IE
window.external.AddFavorite(url , document.title);
}
}