Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Friday, June 24, 2011

To Find if the Page in MOSS is in Design Mode

Some Times we have to make the Jquery/JavaScript run when its not in the design mode.
I don't know how many of us has noted this tag "MSOLayout_InDesignMode" .This is a hidden HTML field present on the page. So using that its simple.

The HTML looks like this:
<input type="hidden" name="MSOLayout_InDesignMode" id="MSOLayout_InDesignMode" value="" />
if (document.getElementById("MSOLayout_InDesignMode").value != "1")
{
//do something
}
else
{
//do something
}

Thursday, June 23, 2011

Print Functionality using Javascript on MOSS

One of the Limitation in SharePoint is having no option to print for the users.Even though there are lot of solutions given by third party vendors or even solution mentioned in Codeplex or SharePoint Tips and Tricks blog I feel this can be done also using Java Script.
function printWebPart(tagid){
var WebPartElementID = tagid;
var bolWebPartFound = false;
if (document.getElementById != null)
{
//Create html to print in new window
var PrintingHTML = '\n\n';
//Take data from Head Tag
 if (document.getElementsByTagName != null)
{
var HeadData= document.getElementsByTagName("HEAD");
if (HeadData.length > 0)
PrintingHTML += HeadData[0].innerHTML;
}
PrintingHTML += '\n\n\n';
var WebPartData = document.getElementById(WebPartElementID);
if (WebPartData != null)
{
PrintingHTML += WebPartData.innerHTML;
bolWebPartFound = true;
}
else
{ bolWebPartFound = false;
 alert ('Cannot Find Web Part');
 }
} PrintingHTML += '\n\n'; //Open new window to print
if (bolWebPartFound)
{
//alert("clicked print");

var PrintingWindow = window.open("","PrintWebPart", "toolbar,width=800,height=600,status=yes,resizable,menubar");
PrintingWindow.document.open();
PrintingWindow.document.write(PrintingHTML);
PrintingWindow.document.close();
// Open Print Window
PrintingWindow.print();
PrintingWindow.close();
 }
}