Thoughts From Eric Archive

Safari SyntaxError

Published 19 years, 11 months past

In pursuit of better JavaScript skills, I’ve encountered a Safari problem that may be a limitation in the browser, or it may be my coding.  I have a temporary test file demonstrating what’s happening.  In Firefox, everything works as I’d hoped it would, but in Safari, all I get is an error on the JavaScript console stating:

SyntaxError – Parse error

Here’s the function in which the error occurs, with the offending line emphasized:

function Test(a,b) {
	this.a = a;
	this.b = b;
	this.c = new (function Inner() {
		this.x = 'woo';
	});
}

As I say, here’s the temporary test file in case you want to see the entire script.

My long experience with CSS and browser handling  of it teaches me that just because something works in one browser, that doesn’t mean it’s supposed to work at all.  Therefore, it could be that Firefox is letting me be sloppy, and Safari is telling me I’ve messed up; or it could be that Firefox is right, and Safari has a problem.

So which is it?  If it’s the former, how can I do the same thing I’m trying to do, except correctly?  If it’s the latter, are there any simple workarounds to get Safari to behave?

Thanks for any help.

Update: Lachlan Hunt rides in to the rescue by pointing out what probably should have been painfully obvious, but like I say, I’m new to this.  The solution here:

function Test(a,b) {
	this.a = a;
	this.b = b;
	this.c = new function() {
		this.x = 'woo';
	};
}

I’m still not 100% certain if this was a case of sloppy authoring or a bad browser, but I’m not so concerned with that right now.  I’ll leave up the post in case anyone else encounters a similar problem.

Update redux: Adrian (and, though I didn’t understand what he was saying at the time, Tim) points out a simpler way to do the same thing.


Track/Ping Testing

Published 20 years past

So a while back, Gatekeeper was discovered to silently kill off trackbacks and pingbacks without any notification, something I’d have realized if I had stepped back for a second to think about my coding.  So anyway, a solution was proposed, and I thought it fixed the problem.  Only it didn’t, possibly due to me being sloppy.  I’m honestly not sure.

So anyway, I think this time I’ve really fixed the problem, but to find out, I need to have people trackback and pingback this post.  That’s all; just hit this post with one or the other—or, heck, both. Feel free to make the link back to your site to your home page, your favorite post, your most recent post, your about page… whatever.  Thanks.

Oh, and if your attempt to *back the post fails, leave a comment to let me know.  If you see more than a few comments saying it didn’t work without a response from me, then don’t worry about adding another unless you have information that would explain why the failures are occurring.  Thanks again!


Web Page, Mutated

Published 20 years, 1 day past

One of the first rules of life is that first-hand information is always better than second-hand information.  You can be more certain of something if you’ve seen it with your own eyes.  Anything else is hearsay, rumor, conjecture—an article of faith, if you will.  At the very minimum, you have to have faith that your source is reliable.  The problems begin when sources aren’t reliable.

No, this isn’t a rant about the intelligence screw-ups previous to the invasion of Iraq.  Instead, it’s a warning that inspector programs and saving as “Web page, complete” features can lead you astray.

One such example came up recently, shortly after I mentioned the launch of the new Technorati design.  A question came in:

I did want to ask about the use of -x-background-{x,y}-position as opposed to background-position. If I understand correctly, the -x prefix indicates an experimental CSS attribute, so in what circumstances should one use this sort of experimental attribute instead of an official one?

I’d have been glad to answer the question, if only I’d known what the heck he was talking about.  Those certainly weren’t properties I’d added to the style sheets.  They weren’t even properties I’d ever heard of, proprietary or otherwise.

Just to be sure, I loaded the CSS files found on the Technorati site into my browser and searched them for the reported properties.  No results.  I inquired as to where the reporter had seen them, and it turned out they were showing up in Firefox’s DOM Inspector.

Now, the DOM Inspector is an incredibly useful tool.  You can use it to look at the document tree after scripts have run and dynamically added content.  You can get the absolute (that is, root-relative) X and Y coordinates of the top left corner of every element, as well as its computed dimensions in pixels.  You can see the CSS rules that apply to a given element… not just the everyday CSS properties, but the stuff that the Gecko engine maintains internally.

That’s where the problem had come in.  The DOM Inspector was showing special property names, splitting the background-position values into two different pseudo-properties, and not showing the actual background-position declaration.  This, to me, is a flaw in the Inspector.  It should do two things differently:

  1. It should show the declaration found in the style sheet.  There should be a line that shows background-position and bottom left (or whatever), because that’s what the style sheet contains.
  2. It should present the internally-computed information differently than the stuff actually taken from the style sheet.  One possibility would be to show any internal property/value pair as gray italicized text.  I’d also like an option to suppress display of the internal information, so that all I see is what the style sheet contains.

The person who asked why I was using those properties wasn’t stupid.  He was just unaware that his tool was giving him a distorted picture of the style sheet’s contents.

Don’t think Firefox is the only culprit in unreliable reporting, though.  Anyone who uses Internet Explorer’s save as “Web page, complete” feature to create a local copy for testing purposes isn’t getting an actual copy.  Instead of receiving local mirrors of the files found on the Web server, they’re getting a dump from the browser’s internals.  So an external style sheet will actually be what the browser computed, not what the author wrote.  For example, this:

body {margin: 0; padding: 0;
  background: white url(bodybg.gif) 0 0 no-repeat; color: black;
  font: small Verdana, Arial, sans-serif;}

…becomes this:

BODY {
	PADDING-RIGHT: 0px; PADDING-LEFT: 0px;
BACKGROUND: url(bodybg.gif) white no-repeat 0px 0px;
PADDING-BOTTOM: 0px; MARGIN: 0px; FONT: small Verdana, Arial, sans-serif;
COLOR: black; PADDING-TOP: 0px
}

Okay, so it destroys the authoring style, but it isn’t like it actually breaks anything, right?  Wrong.  For some reason, despite IE treating the universal selector correctly, any rule that employs a universal selector will lose the universal selector when it’s saved as “Web page, complete”.  Thus, this:

#sidebar {margin: 0 74% 3em 35px; padding: 0;}
#sidebar * {margin: 0; padding: 0;}

…becomes this:

#sidebar {
	PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px;
MARGIN: 0px 74% 3em 35px; PADDING-TOP: 0px
}
#sidebar  {
	PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px;
MARGIN: 0px; PADDING-TOP: 0px
}

Oops.  Not only can this mean the local copy renders very differently as compared to the “live” version, it’s also very confusing for anyone who’s saved the page in order to learn from it.  Why in the world would anyone write two rules in a row with the same selector?  Answer: nobody would.  Your tool simply fooled you into thinking that someone did.

Incidentally, if you want to see the IE-mangled examples I showed in a real live set of files on your hard drive, go save as “Web page, complete” the home page of Complex Spiral Consulting using IE/Win.  And from now on, I’ll always put “Web page, complete” in quotes because it’s an inaccurate label.  It should really say that IE will save as “Web page, mutated”.

So if you’re Inspecting a page, or viewing a saved copy, remember this:  nothing beats seeing the original, actual source with your own eyes.  If you see something odd in your local copy, your first step should be to go to the original source and make sure the oddness is really there, and not an artifact of your tools.


Hacking Weather Widget Hacking

Published 20 years, 1 week past

John Gruber just posted a great article on how to take the Weather Dashboard widget in Tiger and hack it to add a “last updated” time.  It’s not only useful, but it’s also a wonderful introduction to the simplicity of widgets.  If you can hack on XHTML, CSS, and JavaScript—as I expect most visitors to this site can—then you can alter or create a Dashboard widget.

However, there was one thing I didn’t like about John’s hack: he converted the 24-hour time already stored by the widget into 12-hour AM/PM time.  I prefer 24-hour time, as do most people outside the United States (which I am not, but never mind that now), and sticking to 24-hour time makes the script addition even simpler.  So here’s my quick modification of John’s JavaScript to result in a time like “1450” instead of “2:50 pm” or “0307” instead of “3:07 am”.

// Format the time of the last data refresh
var h = object.time.hour;
var m = object.time.minute;
if (h < 10) {
   h = '0' + h;
}
if (m < 10) {
   m = '0' + m;
}
document.getElementById('updatetime').innerText =
   h + m;

Other than that, do everything just like John says to do.  Share and enjoy!


The Pooh Progression

Published 20 years, 1 week past

On Friday, the voice of Tigger died.  Then on Saturday, the voice of Piglet died.

What I want to know is whether Disney security protecting the people who provide the voices of Winnie-The-Pooh, Eeyore, Owl, Gopher, Kanga, Roo, and the rest—or is Disney security, or possibly rogue elements within it, actually behind it all?

Dark times in the Hundred Acre Wood… dark times indeed.


Don’t Read; Speak!

Published 20 years, 1 week past

With the debut of the WSP‘s ATF, a vigorous conversation has gotten underway.  Joe Clark weighed in with some suggestions, Andy Clarke got some rousing comment action, and more have spoken up.  This follows some recent and widely-cited thoughts from Matt May on WCAG 2.0 (with opposing view from Gez Lemon), and from Andy Clarke regarding accessibility and legislation (which inspired the publication of a different view from Andy Budd, not to mention another from Chris Kaminski).  I’ll join the chorus with some points of my own.  (Apparently, my recent post Liberal vs. Conservative was taken as a contribution to the discussion, which it wasn’t meant to be, although the points raised there are definitely worth considering in this context.)

This past May, I delivered a keynote at the 2nd International Cross-Disciplinary Workshop on Web Accessibility in Tokyo, and one of the major points I made was basically this: “Screen readers are broken as designed, and need to become speaking browsers”.

The problem is that screen readers are just that: they read what’s displayed on the screen for a sighted user.  In other words, they let Internet Explorer render the Web page, scrape the visual result, and read that.  I will acknowledge that in the tables-and-spacers era of design, this made a certain amount of sense.  That era is ending; in an important sense, it’s already over and we’re just cleaning up the mess it left.  Which is not to say that table markup is never and should not presently be used for layout purposes, nor is this to say that such markup should be used.  Okay?

What I’m saying is that screen readers need to become speaking browsers: they need to ignore how the page is visually displayed, and read the content.  Use semantic markup when it exists, and otherwise ignore the markup in favor of the actual words, whether it’s plain text or alt text.  Go from the beginning of the document to the end of the document, and ignore the CSS—at least that CSS which is meant for visual media, which these days is pretty much all of it.

You might wonder how a speaking browser should deal with a table-driven site, of which there are still quite a few, he said with some understatement.  One distinct possibility is to do what I just said: ignore the non-semantic markup and read the content.  I can accept that might fail in many cases, so I’ll present a fallback: DOCTYPE switching.  If a document has a DOCTYPE that would put a visual browser into standards mode, then be a speaking browser.  If not, then be a screen reader.

DOCTYPE switching has been, despite a few hiccups, incredibly successful in helping designers move toward standards, and allowing browsers to permit standards-based design without sacrificing every page that’s come before.  The same, or at least a very similar, mechanism could help audible-Web tools.

The WaSP has done great things in their efforts to show vendors why Web design tools should produce standards-oriented markup and CSS.  I sincerely hope they can produce similar results with audible-Web vendors.


Scientificologically Speaking

Published 20 years, 1 week past
And I know that– psychiatry is– is a pseudo science.
— Tom Cruise

Considering that deeply informed opinion was delivered by an adherent to a pseudo religion, I think that we as a species need to take it very seriously indeed.

But I still want to see his new star vehicle.


microformats.org

Published 20 years, 2 weeks past

Along with many other people, I’ve been talking about microformats over the past several months.  Now they have a home: microformats.org.  It’s primarily a community site, a place where people interested in microformats can congregate and share ideas.  It’s also a central point from which new microformats can be created and advanced.  There are pointers to mailing lists, an IRC channel, a weblog, and more.

If you’re interested in a quick introduction to microformats, I highly recommend the leadoff comment in the weblog.  It’s a great introduction to the what, whys, and wherefores of microformats.  The collection of links it’s carrying around is pretty nice, too.

I don’t know for certain how the whole microformats effort will turn out, but more to the point I don’t feel I have to know.  Right now, the low entry barrier and amount of promise shown by microformats makes them extremely compelling, as I think the information on the new site demonstrates.  To echo Tantek, I’ll let the market decide how they’re used, whether they’re a good idea at all, and what shape they take over the long term.

All I know is that I feel the same way about microformats as I felt about CSS, back when I first encountered it.  My instincts tell me, as they did then, that this is important, that it has almost undreamt potential, that it can change the way we build and use the Web.


Browse the Archive

Earlier Entries

Later Entries