Link to home
Start Free TrialLog in
Avatar of Chris Andrews
Chris AndrewsFlag for United States of America

asked on

javascript or jquery to append variable to all urls on page


I need to append a variable to all the <a href> urls on my site if the user is logged in.

If users are logged in, there is a cookie set.  So right now:

1)  I check for the cookie
2) check to see if the variable is already set (so I don't get a redirect loop)
3) Now I need to append "?cache=n" to every url in a href.

It looks like this is possible, I found an example code at  that does something similar, but not exactly, to what I want.

Here's what I've got so far (steps 1 and 2, but they might need some attention too):

if( document.cookie.indexOf('cachen') >= 0) {
      var cachevar;
       var cachevar =;
if(! cachevar){       

//now add something to append "?cache=n" to all the urls on the page


I can use javascript or jquery (version 1.8.1 is loaded on the site), but I am not real familiar with either.  Can you show me how to do this?


Avatar of chaau
Flag of Australia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Andrews


Works great - thank you!

If you don't mind and have a moment, I have a follow up question to this one...'if'-to-avoid-altering-hrefs-that-include.html