Posts

Showing posts with the label Javascript

Session Storage Methods with Expiry

We often need to cache the data in sessionStorage with an expiration timeout.  Session Storage doesn't provide an expiration which is the case with cookies   As cookies allows only 4-5kb of datastorage. sessionStorage allows approx. 5MB of data storage.  Below are some handy method for session storage with expiration.

Usecontext React Simple Example

Have recently bumped upon a very nice and simple example to use UseContext in React to share variable and methods across all the components. Reference Link

SharePoint JSOM Nested Include Properties

Hi All, Sometimes we need to get properties which are nested inside of Listitem and we wonder will it be feasible to make multiple queries for the same. So this scenarios usually occurs when you have to get a set of listitems which are folder and we need to get folder properties of the folder. So you can query it using below method. Just add the sub properties in Include tag

Replace all occurence of String in JavaScript

Hi All, I came across an issue in JavaScript where i was not able to replace all the occurrences of a string in another string. A simple string.replace would only replace the first occurence. str.replace("hello", 'hi'); We can make a small tweak in the existing code and make it work.Below is an example. str.replace(new RegExp('hello', 'g'), 'hi');

Read Web Property Bag values SharePoint 2013 , 2016 JSOM

Hi All, Sometimes we just quickly need to check the values of property bag of the web. You can just paste below script in console to get the values of property bag in console. Recommended way 1. Add the script as a as  snippet in Sources >> snippets in Chrome browser 2. Run the script without changing any value

Call a Javascript function after update panel is refreshed

Hi All, We were facing issue to rebind some of our jQuery plugins after the update panel was refreshed. Below is the code which saved us.   var parameter = Sys.WebForms.PageRequestManager.getInstance();     parameter.add_endRequest(function () {        //Reinitialize plugin , any other activity which needs to be done at the end of partial postback     });

Creating custom events for a control in HTML

Hi All, Sometimes we need to create a custom event for a control which we can use it to get the context of the control.Below is a quick method using jQuery to do that. In the below example i have created an init method for input tag. This method can be simply trigger using   $(<SELECTOR>).trigger("<METHODNAME>") Example  <input id="txtName" class="news" init="initializeSection1" />     <input id="txtName" class="news" init="initializeSection2" />     <script>         $(document).ready(function () {             $(".news").bind("init", function (e, data, val) {                 var initializeFunctionName = $(this).attr("init");                 window[initializeFunctionName](e, data, val);             });             $...