Multiplay Labs

tech hits and tips from Multiplay

Archive for May, 2009

Safari Exports Element Ids to Javascript Namespace

without comments

Well seems Safari is totally retarded and exports all html elements to the javascript namespace so if you have the something like the following it breaks:-

<div id="myDialog">my content</div>
<script type="text/javascript>
  var myDialog;
  if ( ! myDialog )
  {
     // Safari never gets here as myDialog = the HTMLElement defined above
     myDialog = new MyDialog( .... );
     ...
  }
  // Safari now fails as the object was never created
  // Instead myDialog is the div element
  myDialog.myFunction();
</script>

This was experienced here in Safari 4 build 528.16 and reported by users in Safari 3 as well.

Written by Dilbert

May 28th, 2009 at 5:54 pm

Posted in Hackery