-2

Possible Duplicate:
How to create a GUID / UUID in Javascript?
JavaScript: how to generate UUID for Internet Explorer 9?

Is there a way, completely windows platform dependent, of creating a GUID in javascript for IE9. It does not have to support other browsers or OSs.

Thanks!

Community
  • 1
  • 1
kaze
  • 4,299
  • 12
  • 53
  • 74
  • I think it's not depending on the browser. Look at this: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript – Tobi Apr 23 '12 at 06:18
  • "It does not have to support other browsers or OSs" <-- detect IE9 and then disable the support – Michael Buen Apr 23 '12 at 06:27
  • Seems does not show any research effort: http://bit.ly/Jz30et – Michael Buen Apr 23 '12 at 06:36
  • I've seen these questions. Are they actual GUIDs? Or: are they "as good as" an actual system created guid? – kaze Apr 23 '12 at 06:37
  • Thanks for the downvote. I'm NOT looking for a way to create a GUID-like string, but a way of making a system call to generate a true GUID. If that's not possible, I will use a solution like the one that @Kooilnc provided. – kaze Apr 23 '12 at 06:47

2 Answers2

2

A simple search on google leads me to this answer, on StackOverflow. First result.

This is actually what @Kooilnc copy-pasted. He didn't paste the second part however:

However, note in the comments that such values are not genuine GUIDs. There's no way to generate real GUIDs in Javascript, because they depend on properties of the local computer that browsers do not expose. You'll need to use OS-specific services like ActiveX: http://p2p.wrox.com/topicindex/20339.htm

PS: I also suggest to look at this library: node-uuid.

Community
  • 1
  • 1
Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
-2

Here's a small method to create a UUID Test one of the resulting UUIDs here

[edit 2022] See also

var result = document.querySelector("#result");
result.textContent = '10 UUIDs\n---------------------------------------------\n';

for (var i = 0; i < 11; i += 1) {
  result.textContent += createUUID() + '\n';
}

function createUUID() { // RFC 4122-ish
  return Array.from(Array(32))
   .map((e, i) => {
     let someRandomValue = i === 12 ? 4 : (+new Date() + Math.random() * 16) % 16 | 0;
     return `${~[8, 12, 16, 20].indexOf(i) ? "-" : ""}${
       (i === 16 ? someRandomValue & 0x3 | 0x8 : someRandomValue).toString(16)}`;
   }).join("");
}
<pre id="result"></pre>
KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • Thanks for your answer. I will go for this solution if there's no reasonable way of getting a true GUID. – kaze Apr 23 '12 at 07:16