Hi guys,
This is a great tool to track my site, but I've hit a problem with your script.
Basicly, I have got my website (http://tripcast.blogsome.com) down to 1 error in W3C's Page Validator (http://validator.w3.org/).
In your script link, you have a field id="stats_script", which the validator advises that the script tag does not support it ('there is no attribute "id".') What I want to know is, this is essential to your blogging software? If not, then I can remove it to give me 100% valid code.













The simple answer is that im
The simple answer is that im not sure, but i suspect it is not needed. As really all the scrpt tag does is call another script.
Why not take it out for a few hours and let me know if it still works?
Yea, it seems to need this
Yea, it seems to need this tag. My site stats have not registered in about 24 hours, and i've got a yellow light.
I'm going to add the tag back in and see if it starts registering again.
Ok thanks, please let me
Ok thanks, please let me know what happens!
underscore
At the very least, the id shouldn't have an underscore. :)
underscores to be avoided
The JavaScript source
I took a look at the WordPress JavaScript that is included (metrics.performancing.com/wp.js) and found this line:
var js = document.getElementById ("stats_script");It's purpose is so that it can get the base url to include more scripts:
z_base_url = js.src.substring (0, js.src.lastIndexOf ("/") + 1);// include stats.js last
document.write ('<script type="text/javascript" src="' + z_base_url + 'stats.js"></script>');
They wouldn't have to do this if they just included this line in the JavaScript code that you insert into your blog:
var z_base_url = 'http://metrics.performancing.com/';That variable stays defined through any JavaScript called after it, whether it be internal or an external script (using src="..."). I tested this myself and it works.
Problem is, if they need to change where the scripts are located, they're screwed. Secondly, people might accidentally change the JavaScript code in their blog or some malicious script might change the location of z_base_url (not that possible since it loads in page order, and the external Metrics JavaScript is immediately following it) and include a script from a different domain. It's too bad that JavaScript doesn't have a method to find out the location of itself.
After thinking for a little bit, instead of inluding the external script metrics.performancing.com/wp.js, they could include a php file that returns the appropriate JavaScript code and locations. For example, the blog JavaScript would have:
<script type="text/javascript" src="http://metrics.performancing.com/wp.js.php"></script>And wp.js.php would have the line:
<script type="text/javascript" src="<?php echo dirname($_SERVER['SCRIPT_URI']) ?>/stats.js"></script>I tested this quickly also and indeed it worked. It wouldn't be too much of a php hit on the server since it's only two simple operations, but again, it's up to them. And it would make for valid code in the end.
Man, I'd love to work for Performancing! :)
By the way...sometimes the forum was letting me use the <script> tags within <code>...</code> but sometimes it was filtering them out...very frustrating for a long post with lots of previews.
code tag workaround ...
A workaround is to paste the code into PFF and then copy & paste it back into the comment or article form from the source view.
Workaround?
Working from Dave's insights above, I had the following idea... it seems to work, but I'd like someone to verify it.
1. Took the "stats_script" id out of the <script> snippet from Performancing.
2. Added this dummy IMG tag:
<img src="http://metrics.performancing.com/foobar" id="stats_script" style="display: none;" alt="" />
Two things at work here with (2):
a) the id="stats_script" is okay in an IMG tag, but not in a SCRIPT tag, so this will validate now.
b) the IMG tag can pass the proper info to the Peformancing javascript, since it's looking at <code>document.getElementById ("stats_script").src
Thoughts?
--
Tom Sherman
Try it but it seems like it
Try it but it seems like it could work
I think it works
Because I'm still getting stats.
--
Tom Sherman
Re: Workaround?
Very clever solution!
For reference, the id, class, title and style attributes of <script> elements are not valid under HTML 4.01 or XHTML (any). This solution works because it still calls the JavaScript library, the id attribute is valid, the remote script can grab the DOM element via the id and the same src attribute is used to define the URL. Tom even goes so far as to include an empty alt="" attribute, which is also necessary in order for the document to validate as XHTML.
Good temporary solution
This is definitely a good solution for now, and I'll be looking into implementing this as a temporary fix in the WordPress plugin. Maybe they'll implement a solution like I've proposed and the PHP hit wouldn't be too bad. I suppose I could even put a small wp.js.php on my own server for the plugin to load as an alternative to the JavaScript loaded in the default script.
I had to fix my previous post again since the tags were cleaned out after I had posted and left it there for a while...very frustrating.
Good solution
Excellent. Thanks for the solution!
Bottom Line
The performancing metrics, *as is* break the code validity of any site. I suppose it's possible that this is only true for the WordPress script, but if so, that just makes the error more egregious, since it's more clearly unecessary.
That's a pretty horrible situation, considering your market niche...
I guess I'll hack you with the broken image, since putting in the z_base_url leaves a JavaScript error (NOTE: the fact that the broken image works just shows that you might as well be putting the z_base_url in, since I can already set the URL to whatever I want).
Personally I don't see how that could have been a problem, since obviously all it does is put another javascript tag in, and (again, obviously) I could link to any javascript I want anyway.
There is still a problem
The code will not validate if you have the XHTML strict doctype, because you cannot have the inline
tag with a block tag like
. So if you want to make your pages as XHTML then enclose the
tag within a
tag.
Cheers,
Sudar
Post new comment