JavaScript UUID 생성

by JM note

HTML

<script>
  function guid() {
    function s4() {
      return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
    }
    return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
  }

  function show_uuid() {
    document.getElementById('uuid').value = guid();
  }

</script>
<button onclick='show_uuid()'>생성</button>
<input type='text' size='40' id='uuid' />