Monday, June 17, 2013

Create GUID in JavaScript

Case 1:

jquery.guid.js
var guid = jQuery.Guid.New()
but sometimes, it return an error Guid is undefined, etc ...

Case 2: 

function S4() {
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
 
// then to call it, plus stitch in '4' in the third group
guid = (S4() + S4() + "-" + S4() + "-4" + S4().substr(0,3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
alert(guid);
 

Source:

http://guid.us/GUID/JavaScript

0 comments:

Post a Comment