I spent a decent amount of time trying to workaround not being able to access the body onload event of a SharePoint page, including looking at adding JavaScript event handlers programatically, before I came across this… almost an aside in another article.
In order to work around this limitation, SharePoint provides the “_spBodyOnLoadFunctionNames” array. When the body is loaded, the onload event handler executes each function whose name is contained in this array.
So apparently all one has to do to have a JavaScript function execute when the body loads is to add the name of the function (as a string) to that array, a la _spBodyOnLoadFunctionNames.push("functionName"); – simples!
D’oh!
In the end we just wanted to do to much for simple JavaScript so used the awesome jQuery library – which includes the $(document).ready() method to take care of that, but I’m sure the above will help somebody, somewhere, some day.
… it bloody-well is! This post was very nearly “Things that piss me off 5: Internet Explorer” (that one may yet come) but I thought a more descriptive title would help more people struggling with the same problem to find it.
Anyway: background. I am writing a new feature for a Content Management System to allow users to upload files. With a simple bit of javascript I added a “+” button to allow them to add new rows to the form, allowing them to upload multiple files. It looks a bit like this:
Anyway, it would obviously be nice to allow the user to remove a row if they’ve added one or two too many. The obvious solution seems to be to add a “-” button beside each. Easy, right?
Unfortunately Internet Explorer, as per usual, ballses everything up. Because each – button is created dynamically I have to add an EventListener using JavaScript code. No problem so far. That event listener is a simple, one-line:
As each row (the label, field itself (including button) and “-” link) is inside a div, the above code should remove that div and therefore remove the row. And it does… in Firefox. Try it in Internet Explorer and you get a message telling you “Error: ‘this.parentNode.parentNode’ is null or not an object”.
Whhhaaa?!
Don’t you just hate when you can easily find something your code claims it can’t? Am I the only one who screams “It’s right f**king there!!” at my monitor? In this case, the problem seems to boil down to IE’s supid, proprietary, fucked up way of attaching Event listeners. When you use Mozillas the W3C standard addEventListener method to attach a listener to an event, “this” in the event handler refers to the object which the event is called on. Obvious, yes? However when you use IE’s attachEvent instead, IE doesn’t seem to act in the same way. Apparently, instead, IE sets “this” in an event handler to the window object instead of the calling/event object! Another good job from Micro$oft!
Apparently it’s can be overcome, but that involves a lot of code and I refuse in principle to do that much inelegant hacking for something so simple. It’s much easier (and principled) to do this:
The Google Streetview Car (Streetcar?) spotted in Belfast (Queen’s Road, Titanic Quarter) yesterday morning whilst I sat in my car pondering on the future. A bloke on my Twitter watch list described seeing a similar car in Sheffield just an hour or so previously, or I wouldn’t have even realised it was the Google car (assuming he’s correct of course).
OK, the video’s not up to much, but I had been trying to take a photo instead!
I love PHP. It’s everywhere. All my sites are written in it. My CMS is written in it. My blog engines, WordPress and b2evolution, are written in it. It’s free. It runs on any platform. Hosts all support it. With PHP 5 they’ve even done a lot of work on PHP4’s main downfall – lack of OOP support.
One thing really pisses me off though – it’s totally inconsistent. Consider these two functions:
In in_array the first parameter is what you’re looking for and the second is what you’re looking in (more or less consistent with preg_match). In strstr (and its derivatives) this order is reversed. Who on Earth let that slip through? I’m yet to find a free text editor that will tell you which parameters a given function expects (Dreamweaver does a decent job but it’s bloody expensive for a text editor!) the way Visual Studio does for C#, which I use a lot in work. Given that situation, you’d expect consistency in this sort of thing. Apparently not so. Instead, every time I want to use one of these functions I have to do a quick Google to bring me to the PHP manual page to tell me which order the parameters come in.
Of course they can’t even fix that without breaking backwards compatibility either, so we’re probably stuck with it. Bloody marvellous!
I haven’t come across anything truly groundbreaking in Firefox 3, possibly because I’ve become accustomed to much of the feature set through the Betas and RCs, but there are one or two improvements that are quite useful (as well as a couple of regressions unfortunately).
Wee Niggles
First the bad. When you view Page Info from the context menu it doesn’t give a link to the CSS file in the Media tab any more. I was sure it was there in 2 and a quick google confirmed this. This really sucks – I can’t see why they’ve taken it out.
Secondly, when I was looking through the options to try and return the aforementioned CSS links, I discovered Firefox had decided it was going to automatically download any future updates when they were discovered (I promptly switched the option to “Ask me…”). Bad Firefox.
Magic Address Bar
The good is good though. It doesn’t seem like it at first, but to my mind the biggest improvement of all is the address bar. Sure they’ve added a “Most Visited” folder to your bookmarks toolbar which (shockingly, given the title) contains a list of the sites you visit most frequently, but the address bar has some great, if not immediately obvious, usability improvements.
Looks like the excitement is a little bit premature. Not just yet, but at 6pm BST the newest version of Mozilla’s FireFox web browser will be released. Mozilla want Firefox 3 to break the record for the most downloads in 24 hours, which begs the question as to why they pissed off Australasia and half of Asia by promoting Download Day as today, 17th June, when they’re not making the new version available until 10am Pacific Time which means the aforementioned regions will not see the download released until it is 18th June there. That’s without even considering yours truly and millions of other Europeans who will be finished their days work.
I spent ages trying to figure out why my new installation of WAMP Server 2 wouldn’t parse my PHP and was spitting it out exactly as-is in the source file. I hoked around in the VirtualHost configuration, because the PHPMyAdmin that comes with WAMP Server was working fine so it had to be something wrong in the VirtualHost that I just configured that was stopping .php files being sent to the PHP parser, yes? No.
As it turns out, it’s much simpler than that. Apache was sending the file to PHP to be parsed, but PHP was ignoring my code. Why? WAMP Server 2 comes with “short open tags” turned off (this may be a general PHP or PHP 5 thing, though not sure). Click WAMP -> PHP -> php.ini to edit the aforementioned file and find the line:
short_open_tag = Off
Replace Off with On et voila.
The ‘more correct’ though long-winded solution is to replace all your <? opening tags with <?php if you’re really keen (though that’ll also mean replacing <?= with <? echo). Me, I think I like my short tags.
I recently moved this site to a new host because of ongoing problems with my previous hosts. Thanks to some intermittent database errors I’d decided it would be prudent to do my first backup in some time at the start of last week. By the end of that week they’d deleted my account, so I suppose I should be grateful their database server was so f**ked. Nevertheless, the move caused a few issues when my new hosts told me the complete backup I uploaded to them was corrupt. I can only assume (because some backups were corrupt and others weren’t) that it was due either to encrypting the archives using AES in Winzip or decrypting them in 7zip.
Anyway, that meant manually creating the accounts, setting up the mail accounts and subdomains in them, extracting the root folders (public_html, mail etc) individually and manually importing the SQL backup. Everything was relatively painless (if dull) however Fantastico wouldn’t recognise my WordPress installations (I had two). To persuade Fantastico that there really were a couple of WordPress blogs I had to do two things:
Extract the \.fantasticodata\WordPress files from the zip (in this case it was called nerd.steveferson.com| ) and upload it to the same location in the FTP server. Of course that bar | made Windows barf, so you’d need to rename it (e.g. using an underscore instead) and replace the bar after uploading it via the FTP client (FileZilla didn’t seem to have a problem doing this).
I think this is might be because the blog’s in the root of a subdomain, but I also had to upload a file called installed_in_root.php from \.fantasticodata to that location on the server.
Once I did this, Fantastico picked up the blog and allowed me to upgrade WordPress to 2.5.1 – no hassle.
I hart lolcatz so much dat wun dai I thoughted “I can has lolcatz wen I makes teh pooter turn on?” So I maded a Vista gadjit an now I has new lolcatz every dai.
If u hart lolcatz liek mee an wants lolcatz in ur pooter makin u laff, downlodes mah gadjit. I has tested it 4 liek rly long time. It rly works, srsly. An evry1 needses moar lolcatz.
Just now I’ve used the same tool to fix a similar (I think) problem on IIS7 on Vista. I was trying to get some practice with ASP.NET. I’ve already got IIS7 and I’ve already got the .NET Framework 2.0 installed. However it seemed, again, that IIS wasn’t aware of the Framework’s existence. When I tried to browse to a simple Hello World page I was greeted with an HTTP 404 (404.3 to be precise) informing me that:
“The page you are requesting cannot be served because of the extension configuration. If the p age is a script, add a handler. If the file should be downloaded, add a MIME map.”
Despite the different error messages it appeared to be a similar problem. Apparently it was. That wonderful little solution again:
Start -> Cmd
Navigate to your .NET Framework directory (e.g. C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727)