title: Javascript window.open cuts off link at special character
body: <p>This is my second question on stackoverflow so please forgive any unintended newbieness. </p>
  
  <p>I checked the suggested duplicate post - <a href="https://stackoverflow.com/questions/9060294/how-to-pass-special-characters-to-javascript-window-open-in-url-using-paper-add">How to pass special characters to javascript window.open in URL using paper.add method?</a></p>
  
  <p>but that post does not contain an answer.</p>
  
  <p>Basically what I am trying to achieve is to open a file link (my users are all IE) via javascript. Said link may contain a hash character - "#". If it does, the link gets cut off at the hash tag (and does not work, obviously).</p>
  
  <p>I found a way around this by encoding the URI and then opening it in the same window. My requirement is to open it in a new tab. I have not been able to figure out how to do this with window.open().</p>
  
  <p>The below code opens the file in the same window. No good.</p>
  
  <pre><code> $(document).on("click", "#LANPath", function (e) {
      var str = 'J:/Product Compliance/FACTs/+FACTS Test/Test_Attachment_Single_Premium_Group_App_Sample # Copy.pdf';
  
      var url = encodeURIComponent(str);
      var url2 = url.replace(/#/g, '%23');
  
      window.location.href = 'file:///' + url2;
  });
  </code></pre>
  
  <p>The below function cuts off the url at the # and does not open anything. Worse yet.</p>
  
  <pre><code>$(document).on("click", "#LANPath", function (e) {
      var str = 'J:/Product Compliance/FACTs/+FACTS Test/Test_Attachment_Single_Premium_Group_App_Sample # Copy.pdf';
  
      var url = encodeURIComponent(str);
      var url2 = url.replace(/#/g, '%23');
  
      var win = window.open( 'file:///' + url2, '_blank');
      win.focus();
  });
  </code></pre>
  
  <p>Many thanks in advance.</p>