Set query string to all links - Javascript jQuery

Javascript examples for jQuery:String

Description

Set query string to all links

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.9.1.js"></script> 
  <script type="text/javascript">
    $(function(){/*from www. jav  a 2  s .c o  m*/
var querystring = 'myquerystringtoadd';
$('a').each(function()
{
 var href = $(this).attr('href');
 href += (href.match(/\?/) ? '&' : '?') + querystring;
 $(this).attr('href', href);
});
    });

      </script> 
 </head> 
 <body> 
  <a href="url.html?abc=def">1</a> 
  <a href="url.html">2</a>  
 </body>
</html>

Related Tutorials