Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 7th, 2004, 07:53 AM
rbd rbd is offline
Registered User
 
Join Date: Oct 2004
Location: , , USA.
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
Reply With Quote
  #2 (permalink)  
Old October 7th, 2004, 09:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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");
    }
}
Reply With Quote
  #3 (permalink)  
Old October 7th, 2004, 11:31 AM
rbd rbd is offline
Registered User
 
Join Date: Oct 2004
Location: , , USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

rbd

Reply With Quote
  #4 (permalink)  
Old October 8th, 2004, 12:54 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #5 (permalink)  
Old November 17th, 2006, 12:47 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
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);

Reply With Quote
  #6 (permalink)  
Old November 17th, 2006, 03:21 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #7 (permalink)  
Old January 17th, 2007, 07:39 AM
Registered User
 
Join Date: Jan 2007
Location: Philadelphia, PA, USA.
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


Reply With Quote
  #8 (permalink)  
Old January 17th, 2007, 08:01 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #9 (permalink)  
Old November 20th, 2007, 12:14 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.