Chris Andrews
asked on
javascript or jquery to append variable to all urls on page
Hi,
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 http://jsfiddle.net/6U749/ 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):
<script>
if( document.cookie.indexOf('c achen') >= 0) {
var cachevar;
var cachevar = location.search;
if(! cachevar){
//now add something to append "?cache=n" to all the urls on the page
}}
</script>
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?
Thanks,
Chris
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 http://jsfiddle.net/6U749/ 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):
<script>
if( document.cookie.indexOf('c
var cachevar;
var cachevar = location.search;
if(! cachevar){
//now add something to append "?cache=n" to all the urls on the page
}}
</script>
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?
Thanks,
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chaau,
If you don't mind and have a moment, I have a follow up question to this one... https://www.experts-exchange.com/questions/28687976/Need-jquery-'if'-to-avoid-altering-hrefs-that-include.html
Chris
If you don't mind and have a moment, I have a follow up question to this one... https://www.experts-exchange.com/questions/28687976/Need-jquery-'if'-to-avoid-altering-hrefs-that-include.html
Chris
ASKER