Office 365 and JQuery

By Gord at July 17, 2011 00:48
Filed Under:

I’ve been tinkering with Office365 on and off for a little while.  While it seems as if Microsoft has done a great job, things get a little difficult when you go beneath the surface. 

 

One such issue is creating a generally useful public facing website.  While the basic tools are ok for most, anything beyond the basics starts to really get messy.  Currently there is no way to host a custom .net application, and no easy way to integrate JQuery.  I did manage to find a work-around to make it all work though.

 

Fyi, if you want to use your own JQuery and JQuery UI, you’ll need to upload the files to your "website documents” and reference them in the script below.

 

So, how do you get JQuery working on Office 365 public website, well, thank goodness there are smart folks over on StackOverflow to make it easy.  What you’ll have to do is use the HTML Gadget and add the following script:

 

<script type="text/javascript" defer="defer">
(function() {
function getScript(url,success){
var script=document.createElement('script');
script.src=url;
var head=document.getElementsByTagName('head')[0],
done=false;
script.onload=script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
done=true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',function(){
// YOUR CODE GOES HERE AND IS EXECUTED AFTER JQUERY LOADS
});
})();
</script>

 

Inside the script above, you can insert whatever JQuery you need to run. If you need to add more javascript such as JQuery UI, you can chain off the getScript function like this:

 

getScript('http://myurltojquery.js',function(){
getScript('http://myurltojqueryUI.js',function(){
//your tab code here
})
});

 

for more details, you can visit this link to the original post on Stack Overflow

About the author

Gord graduated from Carleton University with a bachelors of Computer Science with minors in both Philosophy and Mathematics.  His post graduate career started in 2005 as a Systems Administrator until becoming a .Net Web Developer 2 years later.  Since then, he has moved on to being a more generic Systems Developer, focusing on intersystem communication, design, and architecture.

Page List