View Full Version : javascript based on CSS?
Nimai
Feb-20-2007, 02:10 PM
I have some JavaScript (actually, it's the code from statcounter.com) in my footer. However, I would like to not run the script if I'm .loggedIn. Is there a way to test for being logged-in from javascript?
Thanks~
ivar
Feb-20-2007, 02:29 PM
I have some JavaScript (actually, it's the code from statcounter.com) in my footer. However, I would like to not run the script if I'm .loggedIn. Is there a way to test for being logged-in from javascript?
Thanks~Why don't you just setup your statcounter account to not count hits from your IP?
If you have a dynamic IP, you can also have a cookie set, which makes sure your visits are not counted.
Nimai
Feb-20-2007, 02:58 PM
Yup, yup, and yup. I knew I would have to get one "make-sure-the-power-cord-is-connected" stock support response before I got an answer to my actual question! ;)
:rofl
Seriously, though- I do have a dynamic IP, and I have tried their "block" cookie, but it vanishes (expires? gets deleted?) without notice very frequently. On their forums, there's even a sticky about how the blocking-cookie always disappears, and what you can do to work around it.
I figure there might be a way using SmugMug's rich set of CSS decorations to just get rid of the tracker all together when I'm logged in.
Nimai
Feb-20-2007, 04:11 PM
Argh~ Sorry for the sarcasm there...
I think I may be on to something:
if(document.getElementById('homepage').className.indexOf('loggedIn')>=0) ...
This looks like the way to test for being logged-in using javascript.
Nimai
Feb-20-2007, 06:37 PM
Alrighty - I've pretty much got it functional, but not pretty. :nah
Here's my modified statcounter code (numbers changed to asterics):<!-- Start of StatCounter Code -->
<s c r i p t type="text/javascript" language="javascript">
var sc_project=*******;
var sc_invisible=0;
var sc_partition=21;
var sc_security="*******";
// I added this in here to inject the statcounter script only if I'm not logged in
if(document.getElementById('homepage').className.indexOf('loggedIn')<0) {
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.type = 'text/javascript';
script.language = 'javascript';
script.src = "http://www.statcounter.com/counter/counter.js";
head.appendChild(script)
}
</s c r i p t>
<noscript><a href="http://www.statcounter.com/" target="_blank"><img src="http://c22.statcounter.com/counter.php?sc_project=******&java=0&security=******&invisible=0" alt="free web site hit counter" border="0"></a> </noscript>
<!-- End of StatCounter Code --><br><a href="http://my.statcounter.com/project/standard/stats.php?project_id=******&guest=1">View My Stats</a>
The "not pretty" part is that when that "injected" script does execute (I'm not logged in) the counter gets put at the bottom-bottom of the page, bellow the smugmug footer and everything. I's supposed to be right above the "View My Stats" link.
I tried to appendChild to getElementById("bodyWrapper") instead of to head but then no counter showed up at all...
Anyway, I'm tempted to go with this for now. I don't really want/need a counter on my pages. I may just change my statcounter settings to not display a couter, and just track away - but not while I'm logged in! :D
vBulletin v3.5.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.