Guest User

Untitled

a guest
Jul 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. var url = window.location.href;
  2. if (url.indexOf('?') > -1){
  3. url += '&param=1'
  4. }else{
  5. url += '?param=1'
  6. }
  7. window.location.href = url;
  8.  
  9. window.location.search += '&param=42';
  10.  
  11. location.href = location.href + "&parameter=" + value;
  12.  
  13. https://stackoverflow.com/?&param=1&param=1&param=1&param=1&param=1&param=1&param=1&param=1&param=1
  14.  
  15. function URL_add_parameter(url, param, value){
  16. var hash = {};
  17. var parser = document.createElement('a');
  18.  
  19. parser.href = url;
  20.  
  21. var parameters = parser.search.split(/?|&/);
  22.  
  23. for(var i=0; i < parameters.length; i++) {
  24. if(!parameters[i])
  25. continue;
  26.  
  27. var ary = parameters[i].split('=');
  28. hash[ary[0]] = ary[1];
  29. }
  30.  
  31. hash[param] = value;
  32.  
  33. var list = [];
  34. Object.keys(hash).forEach(function (key) {
  35. list.push(key + '=' + hash[key]);
  36. });
  37.  
  38. parser.search = '?' + list.join('&');
  39. return parser.href;
  40. }
  41.  
  42. location.href = URL_add_parameter(location.href, 'param', 'value');
  43.  
  44. function gotoItem( item ){
  45. var url = window.location.href;
  46. var separator = (url.indexOf('?') > -1) ? "&" : "?";
  47. var qs = "item=" + encodeURIComponent(item);
  48. window.location.href = url + separator + qs;
  49. }
  50.  
  51. function gotoItem( item ){
  52. var url = window.location.href;
  53. url += (url.indexOf('?') > -1)?"&":"?" + "item=" + encodeURIComponent(item);
  54. window.location.href = url;
  55. }
  56.  
  57. location.href = location.href + "&parameter=" + value;
Add Comment
Please, Sign In to add comment