Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 26th, 2012  |  syntax: None  |  size: 1.41 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Bug in IE when using Javascript to change a form action, when method=get and URL contains a hash
  2. <script type="text/javascript">
  3. function changeURL() {
  4.     var myform = document.getElementById('myform');
  5.  
  6.     myform.setAttribute("action", "page2.html#hello");
  7.  
  8.     return false;
  9. }
  10. </script>
  11.  
  12. <form id="myform" action="page1.html" method="get" onsubmit="changeURL()">
  13.     <input type="submit">
  14. </form>
  15.        
  16. myform.action = "page2.html#hello";
  17.  
  18. myform.attr("action", "page2.html#hello");
  19.  
  20. myform.get(0).setAttribute("action", "page2.html#hello");
  21.        
  22. <script type="text/javascript">
  23. function changeURL() {
  24.     var hidden = document.createElement('input');
  25.     hidden.setAttribute("type", "hidden");
  26.     hidden.setAttribute("name", "hash");
  27.     hidden.setAttribute("value", "hello");
  28.     var myform = document.getElementById('myform');
  29.     myform.setAttribute("action", "page2.html");
  30.     myform.appendChild(hidden);
  31.     // return false;
  32. }
  33. </script>
  34. <form id="myform" action="page1.html" method="get" onsubmit="changeURL()">
  35.     <input type="submit">
  36. </form>
  37.        
  38. <script type="text/javascript">
  39. var qs = window.location.search.substring(1);
  40. var qsarr = qs.split("&");
  41. for (var i=0; i<qsarr.length; i++) {
  42.     var tarr = qsarr[i].split("=");
  43.     if (tarr[0]==="hash") {
  44.         window.location.hash = tarr[1];
  45.     }
  46. }
  47. </script>
  48.        
  49. <form action="#test" method="get">
  50.     <input type="text" value="test" />
  51.     <input type="submit" />
  52. </form>