title: Javascript bookmarklet: how to replace URL parts?
body: <p>I'm trying to create a Javascript bookmarklet, which would extract a numeric ID from an URL:</p>
  
  <pre><code>   http://site-1/script-1.php?ID=12345678&amp;other-params
  </code></pre>
  
  <p>and then redirect the browser to a new URL:</p>
  
  <pre><code>   http://site-2/script-2.php?id=12345678
  </code></pre>
  
  <p>I've searched net for bookmarklet examples and I have 2 questions please:</p>
  
  <p>1) Do I need to place my JS-code inside a <strong>void</strong>?</p>
  
  <pre><code>javascript:void(XXX);
  </code></pre>
  
  <p>What does <strong>void</strong> mean in this context?</p>
  
  <p>2) Should I use <strong>location.href</strong> for reading the old URL and assigning a new constructed URL? I'm asking because I've seen many strange pieces of code, like <strong>String(location.href)</strong> etc. - like it needs some <em>casting</em> to String (does it?)</p>
  
  <p><strong>UPDATE:</strong> I've tried the following code, but nothing happens in Chrome unfortunately, when I'm on the old page and click my bookmarklet (hoping to navigate to the new page):</p>
  
  <pre><code>javascript:void (
      if ( var match = location.search.match(/id=(\d+)/i) ) 
          location = 'http://site-2/script-2.php?id=' + match[1];
  )
  </code></pre>
  
  <p>(I've added line-breaks above and yes I'm trying to use a single "=")</p>
  
  <p><strong>UPDATE 2:</strong> My 2nd try - just trying to display a new URL:</p>
  
  <pre><code>javascript:void (
      var match = location.search.match(/ID=(\d+)/);
      alert('http://site-2/script-2.php?id=' + match[1]);
  )
  </code></pre>
  
  <p>but still nothing happens, when I click the bookmark at the bookmarks bar. And I see in Google Chrome console:</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token var
  </code></pre>