Answered by:
UUID/GUID Javascript

Question
-
Is there a way to generate a GUID from Javascript? I looked up at WRT reference, and I can't seem to find an obvious way to generate one.Friday, December 30, 2011 11:03 PM
Answers
-
No Sorry!
I think Jquery may have some functions you can use though:
http://www.bing.com/search?q=jquery+create+guid&go=&qs=n&sk=&form=QBLH-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, January 3, 2012 3:00 PM
- Marked as answer by Jie Bao Monday, January 9, 2012 2:41 AM
Tuesday, January 3, 2012 3:00 PMModerator
All replies
-
No Sorry!
I think Jquery may have some functions you can use though:
http://www.bing.com/search?q=jquery+create+guid&go=&qs=n&sk=&form=QBLH-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Tuesday, January 3, 2012 3:00 PM
- Marked as answer by Jie Bao Monday, January 9, 2012 2:41 AM
Tuesday, January 3, 2012 3:00 PMModerator -
I hit here looking for the same thing. there were many answers at stackoverflow to get a function in javascript. There are too many code snippets there, and one need to pick the right one for self.
For javascript based windows store app - it may be simpler to add a winrt (say commonlib) and add a NewGuid method there. I have used this option.
add a winrt component project say commonlib.
namespace commonlib { public static class GuidUtils { public static System.Guid NewGuid() { return System.Guid.NewGuid(); } } }
-sushil
Monday, March 25, 2013 7:44 AM -
For WinJS you should not drag in the .net runtime but code the winrt component in C++.
Something along the lines of
#include <windows.h> namespace runtime { namespace guid { public ref class GUIDCreator sealed { public: static Platform::String^ CreateGuid() { GUID guid; HRESULT result = CoCreateGuid(guid); if FAILED(result) { throw ref new Platform::COMException(result); } WCHAR guidString[37]; StringFromGUID2(&guid, guidString, 36); return ref new Platform::String(guidString); } }; } }
Tuesday, March 26, 2013 10:12 AM