Just a reminder that this blog has been moved.  The new URL is http://www.troyforster.com.  You can subscribe to the Atom feed at http://feeds.feedburner.com/tforster.

I didn’t even think about it when I first started exploring my new iPhone but in hindsight it makes perfect sense.  The browser is Safari after all.

Unfortunately the only way I have found so far to get bookmarklets on my iPhone is to install Safari on my desktop, delete all pre-installed bookmarks, add my favourite bookmarklets and synchronize.  It’s pretty straightforward but it would be much nicer if I could synch directly with FireFox, my default browser.

After an hour or two of sleuthing I’ve discovered that jQuery 1.2.6 does not set the Content-Type header for HTTP GETs even if you explicitly use the contentType parameter. My understanding of the jQuery rationale is that GETs don’t contain data and therefore a Content-Type header is not required. Unfortunately, Microsoft reckons that GETs returning JSON provide a security risk and that a Content-Type header must be specified. Scott Guthrie explains it here http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx.  

After reading documentation from both camps I can fully understand their opposing views.  Ultimately it is yet another indicator that the responsibility of user protection lies in the browser is blatantly wrong!  If the browser raised a message asking the user if they are ok with a cross domain request and acted according to the response it would render both jQuery’s and Microsoft’s approaches obsolete.

So now I am caught between a rock and a hard place.  I love jQuery and I love Microsoft ASP.NET webservices and I am going to use both in my current projects.  But, if I can not explicitly set the Content-Type header for an .ajax() GET then I have just one choice and that is to use POSTs instead.  Unfortunately this contradicts the notion of using the correct HTTP verbs and removes the possibility of a RESTful API. 

It’s always about compromise.

On March 22 Kate gave birth to Bjorn Thomas Eidsvik.  I’m going to check with Bruce about cross posting some of the images here.  Everyone is doing very well and Bruce seems to have some idea that Bjorn will be competing in the 2034 Winter Olympics.  If little Bjorn is even slightly like his parents I’d say that is a very likely prospect 🙂

image

The Calais Web Service

The Calais web service automatically attaches rich semantic metadata to the content you submit – in well under a second. Using natural language processing, machine learning and other methods, Calais categorizes and links your document with entities (people, places, organizations, etc.), facts (person ‘x’ works for company ‘y’), and events (person ‘z’ was appointed chairman of company ‘y’ on date ‘x’). The metadata results are stored centrally and returned to you as industry-standard RDF constructs accompanied by a Globally Unique Identifier (GUID). Using the Calais GUID, any downstream consumer is able to retrieve this metadata via a simple call to Calais.

This metadata gives you the ability to build maps (or graphs or networks) linking documents to people to companies to places to products to events to geographies to … whatever. You can use those maps to improve site navigation, provide contextual syndication, tag and organize your content, create structured folksonomies, filter and de-duplicate news feeds or analyze content to see if it contains what you care about. And, you can share those maps with anyone else in the content ecosystem.

Yep, I can’t wait…

image

Thank you J-key 🙂

For those of you who don’t know what I’m talking about check out http://reader.google.com.

Here is a slightly updated version of the code from my previous post. The alert box that appears will also display the title and url for the current page. Try the bookmarklet on different pages and you will see it has access to the current document.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Hello World</title>
</head>
<body>
   <a href="javascript:{alert('Hello World!\n\nFrom ' +     
      document.title + ' @ ' + document.location.href);}">
      Hello World!</a>
</body>
</html>

About a year and a half ago I had to create a simple bookmarklet for a work project that captures the url and title of the current page. While there was a lot of information scattered about the internet there was no single step-by-step guide that I could find. As I started to learn more about bookmarklets I gained a greater understanding of their potential. Many new ideas came to mind that I never had time to explore until now.

This series of posts is intended to provide that simple step-by-step guide as well as offer some new and exciting bookmarklets ideas.

How does a bookmarklet work?

A bookmarklet is simply a bookmark that uses the javascript: protocol instead of the more usual http(s): protocol. When you click on a bookmarklet from your Bookmarks toolbar the javascript is executed within the context of the current document.

Since a bookmarklet is just another url it can be presented in a webpage just like any other link. Adding a bookmarklet to the browser Bookmarks toolbar is just a matter of dragging and dropping the link. A bookmarklet can even be put into a folder on the Bookmarks toolbar for less frequest access.

Bookmarklets also have access to any other Uri and are not limited by the same-origin policy. Bookmarklets often inject into the current tab a script tag that points to a completely different domain. Since the script tag has access to both the current document and the remote domain it can pass information between them.

Of course, passing information between domains has security implications. Users adding bookmarklets to their toolbar should do so only in trusted situations. Since there is no universal code signing mechanism for javascript, bookmarklets should be treated with the same caution as any other website.

Known Issues

  • Javascript is required. It goes without saying that any link that uses the javascript protocol is going to require that javascript be enabled in the browser.
  • Framesets present a challenge too since there is no DOM element to attach a child script element to.

Hello World

Lets create the simplest of bookmarklets. No web server is required and the IDE of choice can be as simple as notepad. Copy the following code block into a new text document and save it with an appropriate name. I named mine helloworld.htm but you can choose whatever you like as long as the extension is recognized by your web browser.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>Hello World</title>
</head>
<body>
   <a href="javascript:{alert('Hello World!');}">Hello World!</a>
</body>
</html>

After you have saved the file open up your web browser and navigate to the file or double click it from within Windows Explorer or the Mac Finder. You should see a plain white page with a single link. Drag that link to your Bookmarks toolbar and when you drop it you should see a new button labelled Hello World!

Navigate to a totally unrelated page then click the button.

Assuming there were no accidental typos you should see an alert box with the Hello World! text in it.

Congratulations. You have created your first bookmarklet. In part II of this series I will show you how to do something a little more useful than hello world. I will demonstrate how to manipulate some information from an existing page and present it in an embedded iFrame.