Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 7th, 2004, 07:53 AM
rbd rbd is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating GUID in Javascript

Is there a way to create guid's from javascript? please help.

rbd
 
Old October 7th, 2004, 09:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

On a windows system you can try this:
Code:
function GUIDGen() 
{
    try
    {
        var x = new ActiveXObject("Scriptlet.TypeLib");
    return (x.GUID);
    }
    catch (e)
    {
    return ("error creating GUID");
    }
}
 
Old October 7th, 2004, 11:31 AM
rbd rbd is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you, pgtips. That's exactly what I was looking for.

rbd

 
Old October 8th, 2004, 12:54 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

One small thing. It's safer to write:
Code:
return (x.GUID).substr(0, 38);
Otherwise you can two unwanted characters at the end of the guid.

--

Joe

--

Joe (Co-author Beginning XML, 3rd edition)
 
Old November 17th, 2006, 12:47 AM
Registered User
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys. This was exactly what I was looking for. But the substring stated is incorrect. It should be as follows (and you can condense the code too).

return new ActiveXObject("Scriptlet.TypeLib").GUID.substr(1,3 6);

 
Old November 17th, 2006, 03:21 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

To be fair that depends on what you need, the important thing is to chop off the last two characters of the 40 character string.

--

Joe (Microsoft MVP - XML)
 
Old January 17th, 2007, 07:39 AM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This approach will only work in MS browsers - you can use a javascript to generate the GUID. I have posted a funciton that does just that on my blog:

http://shkedy.blogspot.com/2007/01/c...ient-side.html


 
Old January 17th, 2007, 08:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That's a nice bit of code but not as strict as the Microsoft GUID generation code because this takes more care to ensure uniqueness.


--

Joe (Microsoft MVP - XML)
 
Old November 20th, 2007, 12:14 PM
Registered User
 
Join Date: Nov 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have a similar problem; I need to find a way to uniquely identify a PC; originally I was asked to investigate retrieving the MAC address client-side and programmatically, preferably using JS or Flash. It needs to be a cross-platform, cross-OS solution. Then I stumbled on this thread describing GUID as a possible solution. However, the value *must* be unique, even if it's regenerated, for a particular PC.

I would greatly appreciate any guidance, as I'm a newbie to this area of computers and it's urgent that I solve this problem asap.

Thanks very much,

Selene






Similar Threads
Thread Thread Starter Forum Replies Last Post
Ask IIS for a GUID? Raconteur ASP.NET 2.0 Professional 2 April 25th, 2007 03:25 PM
Javascript Creating XmlDocument Object from String me_zeta HTML Code Clinic 2 November 10th, 2006 12:55 AM
GUID cdhansen BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 October 21st, 2006 04:56 AM
XSLT problem w/ creating JavaScript (FCKeditor) dornad XSLT 0 June 27th, 2006 03:53 PM
Creating a GUID xgbnow Visual C++ 1 May 6th, 2004 11:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.