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

Saturday 5 November 2016

Object doesn't support property or method "attachEvent" in Internet Explorer 11.

I am getting this error on my SharePoint site, which breaks many functionality, like the list AddNew form UI, which is coming out distorted in IE. The error is due to the fact that "attachEvent" is a deprecated function. This error is occurring in the init.js file, which is provided out-of-the-box by SharePoint.

Google Chrome and Mozilla Firefox are handling this error, but IE is unable to do that.

Add the JavaScript code snippet to the JS file used in the master page or used globally.

<script language="javascript">
if (typeof browseris !== 'undefined') {
    browseris.ie = false;
}
</script>


🚀 "Happy Coding" 🚀

Saturday 10 October 2015

SharePoint activates the feature using the REST API.

The REST API provides a simple and easy way to activate features at the site and web level..

I have created simple JavaScript code to activate the feature.

function activateFeature() {
    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/features/add('7e2e2482-9007-4db3-8a7f-9bccd986ec4e')",
        type: "POST",
        headers: {
            "Accept": "application/json;odata=verbose", //return data format.
           "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
// perform operation on the response object.
        },
        error: function (err) {
            alert("Error: " + JSON.stringify(err));
        }
    });
}


Change the URI, and the feature will be activated based on the endpoint.

  1. /web - then feature will be activated at the web level.
  2. /site - then feature will be activated at the site collection level.

Now pass the feature GUID into the add method. You can get the GUID value by using the PowerShell command or by "SharePoint Manager 2013".


🚀 "Happy Coding" 🚀