A PHP Developer's Blog - Joakim Nygård

About jokke.dk

jokke.dk is the personal website of , a software architect, entrepeneur and Mac user living in Copenhagen, Denmark. Read more »

Search the Site

An AJAX Validator

29th January, 2006

I have been experimenting with extending the possibilities of bookmarklets by dynamically including external javascripts from another server, thereby enabling the use of javascript libraries. Combined with modern DOM support in recent browsers, this allows me to alter the currently displayed page by, for instance, injecting a div with content from the included javascript (which of course could also be a parsed PHP script).
My initial experiments worked well - I made a little bookmarklet that would take the URL of the current page, search google for related pages and display the results in a fixed-position div with scrollbars. Very nice, although not that useful.

Then I came up with what I thought would be a really nice thing. Dynamic validation of the current page with a display of any errors, all without leaving the page.
This requires that the source of the page be sent to W3C. Getting the source of the page (minus the doctype, grrr!) can be done with a document.body.parentNode.innerHTML. Unfortunately (in this context only) there is a maximum allowed length of URLs, forcing me to POST the data to W3C.
Now, things are getting a little complicated as POSTing normally requires a form. However, I found that Scriptaculous (among other AJAX frameworks) can do this via a xmlhttprequest. So far so good and testing locally seems to work.

It would seem that the above idea is very similar to the technique used in Cross-site scripting, where data from the user is sent to another (malicious) server without his knowledge. In order words: A security problem. I assume that's why the browser refuses to do anything with my Ajax-code when I try to access a foreign server (like w3.org).

Hot damn, it would have been nice.

« Accessing EFI Firmware on Intel Macs (sort of)  –  ShowOff 0.63 Universal Binary »