Skip navigation.

My comments on ...

... everything bothering me

Safari and HTMLElement.prototype

, ,

As you all know, Safari does not support HTMLElement, which makes it hard to add stuff to all newly created HTML-Elements, Nodes, whatever you might call it.

Fortunately, it supports the semi-standard __proto__ property. Exploiting another "bug", that all HTMLElement(s) are produced from the same prototype, I came up with a neat solution that even works in Safari 1.3 and you can replace functions such as "getAttribute" (go figure!).

var w = window;
if(!w.HTMLElement&&(typeof document.createElement)=="function" // check basics
   &&(var t=document.createElement('a').__proto__) // '__proto__' supported?
   &&t==document.createElement('p').__proto__){ // all HTMLElements the same?
   w.HTMLElement={}; // prevent people from constructing
   w.HTMLElement.prototype=t;
}

This piece uses perfect object detection, i.e. every browser that works this way will be fixed (i.e. all supporting Safaris, maybe KHTML?), while leaving browsers that work differently untouched.

Remember: You saw it here first!

PS: Best used inside a closure, e.g. (function(){ [your code here] })().

n-Dimensional ArraysHow Opera has chosen Me

Comments

avatar
Hi, Grey.

What about insertAdjacentElement and insertAdjacentHTML functions?

I tried to follow this way, but it still doesn't work.

By Quessir, # 24. July 2008, 12:18:17

avatar
You mean you want to replace those two functions, like so?:

var myFunc = function(){/* do stuff */};

HTMLElement.prototype.insertAdjacentElement = myFunc;

alert(HTMLElement.prototype.insertAdjacentElement==myFunc);
//if the property is readonly, this will be 'false'

alert(document.createElement('a').insertAdjacentElement==myFunc);
//if above is true, this should also be true..

If that does not work, then unfortunately I cannot help you much. I don't have Safari 1.3 available anymore (used the Macs in high school), so I can't exactly go and try it out myself, sorry :frown:

By _Grey_, # 24. July 2008, 14:06:46

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

December 2008
M T W T F S S
November 2008January 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31