I am learning the Java CSOM at the moment and have written a little program that creates a sub-site and assigns a masterpage to it. I am embedding all the code directly on the page.

I am finding that the code runs fine in Chrome and not in IE.

When I run the code in Chrome, the following happens:

  1. Once the user enters a title and clicks create a progress animated gif (spinner) is shown
  2. The status is showing as "creating site"
  3. The status changes to "assigning design"
  4. When completed the spinner disappears and the site is there with the correct masterpage

In IE, it is different

  1. The spinner appears but is not animated.
  2. The page refreshes and the site is built in the background
  3. The masterpage is not assigned.

I suspect my code isn't correct but it is very odd that it works different in 2 browsers. I would really appreciate any ideas - many thanks in advance.

    <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script> 
    <script type="text/javascript" src="/_layouts/15/sp.js"></script> 

    /*  Settings */

    function buildSite()
        var siteName = document.getElementById("siteName").value;

        var siteTitle = siteName;

        /* Remove illegal characters and spaces, /g repeats the search for the whole string */
        siteName = siteName.replace(/[&\/\\#,+()$~%.'"|:*?<>{}]/g, '');
        siteName = siteName.replace(/ /g,'-');

        /* Stop the user pressing the button more than once */

        document.getElementById("btnSubmit").disabled = true;   

        /* Check the site name is not empty */
        if (siteName.length == 0) {
            alert("Site name cannot be empty.");
        else {


    function SiteBuilder(site, title) {
    document.getElementById("status").innerHTML = "Creating site";

    var context;
    var website;

    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();

    clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);

    function onRequestSucceeded() {

    function onRequestFailed(sender, args) {
        alert('Error: ' + args.get_message());

    clientContext = SP.ClientContext.get_current();
    website = clientContext.get_web();

    var webCreationInfo = new SP.WebCreationInformation();



    clientContext.executeQueryAsync(onCreateSucceeded, onRequestFailed);

    function onCreateSucceeded() {
    /* Site is created, now set the MasterPage */ 
    var fullURL = website.get_url() + "/"+site;

    function SetMasterPage(siteURL)
        document.getElementById("status").innerHTML = "Assigning design";
        var context;
        var web;
        var strMasterPageUrl = '/_catalogs/masterpage/biosilta.master';

        context = new SP.ClientContext(siteURL);
        web = context.get_web();

        //Set Site Master Page

        //Set System Master Page


        context.executeQueryAsync(function () {

        /* Everything worked so allow user to add another site */

        document.getElementById("btnSubmit").disabled = false;  
        document.getElementById("status").innerHTML = "";

    }, function (sender, args) {

        alert("Error: " + args.get_message());



    function cleanup()
        document.getElementById("btnSubmit").disabled = false;  
        document.getElementById("status").innerHTML = "";




    #enterSite {
    padding-top: 4px;

    #btnSubmit {
    margin-left: 0px;


<label id="enterSite">Enter a title for the site
<input id="siteName"  style="font-size:1.0em" type="text"></input>
<button id="btnSubmit" onclick="buildSite()">Add site</button>
<p id="status" ></p>
<div id="spinner" style="visibility:hidden">
<img src="/Style%20Library/Images/spinnerLarge.gif"> </img>


  • im just guessing, but could have to do with the button and postback. Could you try using a <input type="button" onclick="buildSite()" /> instead and see if the behaviour is the same – Anders Aune Sep 27 '14 at 20:17
  • What version of IE are you using? Have you tried testing against different versions of IE? – Derek Gusoff Sep 28 '14 at 1:32
  • Also, what version of SharePoint are you on in terms of patch level (i.e. cumulative updates and service packs). It's a stretch, perhaps, but this may have been fixed in a subsequent update to SharePoint. Also, do you get any client-side errors in the debug console in IE? – nsturdivant Sep 28 '14 at 3:15
  • Hi -- thanks for the responses. In order: Changing to <input type> has no effect on the error. I am using IE 11, switching to compatibility view doesn't help. There are no errors in the javascript console. It is SharePoint online so I can't influence the version. Thanks again for any ideas, it is driving me crazy! – brendan Sep 28 '14 at 10:08
  • There are several places where browsers are known to function differently. It is not entirely uncommon to run into this problem. something as simple as parsing regex can cause a failure like this. using the debugger to step through the code is a reasonable way to check the values in your variables to see if they are what you expect. Also your code has a few nice breakpoints where you could split the code in a divide and conquer strategy. – ghangas Jan 14 '15 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.