Page 1 of 1

Cross browser charts???

Posted: Sat Aug 19, 2006 12:39 am
by alex.barylski
I just tried the following code:

Code: Select all

window.attachEvent("onload", alert("Onload fired"));
And it worked on IE6.0.2900, FF1.5.0.6 and Opera 9.01 :P

Thats awesome, as I only care to support the latest browsers and apparently I don't have to write a cross browser wrapper to do it...so long as the latest and greatest technology is used :P

I'm curious though, I thought addEventListener was the w3c standard...which I also just tested and it too worked for the 2 browsers... :? 8O

So which one should I go with, as I don't care about backwards compatability, this won't be released for quite some time to come anyways... :P

I suppose W3C would be the smart choice...

What I wanted to know was, does anyone know of a chart, website which keeps track of browser differences and amount of w3c DOM supported in each???

Cheers :)

Posted: Sat Aug 19, 2006 12:43 am
by feyd

Posted: Sat Aug 19, 2006 12:46 am
by alex.barylski
Blew right by that one...guess I'll giver' a second look :P

Posted: Sat Aug 19, 2006 6:58 am
by Ollie Saunders
This filters out a whole load of browser JS implementation variables:

Code: Select all

var d = document;
var OF_Toolkit = {
	bind:function(dObj, sEvent, fnHandler) 
	{
		if (dObj.attachEvent) {
		    dObj.attachEvent('on'+sEvent, fnHandler); 
		} else if (dObj.addEventListener) {
		    dObj.addEventListener(sEvent, fnHandler, false); 
		} else { 
		    dObj['on'+sEvent] = fnHandler; 
		}
	},
	unbind:function(dObj, sEvent, fnHandler) 
	{
		if (dObj.detachEvent) {
		    dObj.detachEvent('on'+sEvent, fnHandler);	
		} else if (dObj.removeEventListener) { 
		    dObj.removeEventListener(sEvent, fnHandler, false); 
		} else {
		    dObj['on'+sEvent] = null; 
		}
	},
	formatEvent:function(oEvent) 
	{
		if(typeof oEvent.srcElement != 'undefined') {
	        oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
	        oEvent.eventPhase = 2;
	        oEvent.isChar = (oEvent.charCode > 0);
	        oEvent.pageX = oEvent.clientX + d.body.scrollLeft;
	        oEvent.pageY = oEvent.clientY + d.body.scrollTop;
	        oEvent.preventDefault = function () { this.returnValue = false; };

	        if (oEvent.type == "mouseout") oEvent.relatedTarget = oEvent.toElement;
	        else if(oEvent.type == "mouseover") oEvent.relatedTarget = oEvent.fromElement;

	        oEvent.stopPropagation = function () { this.cancelBubble = true; };

	        oEvent.target = oEvent.srcElement;
	        oEvent.time = (new Date).getTime();
	    }
	    return oEvent;
	},
	getEvent:function() 
	{
	    if (window.event) {
	        return this.formatEvent(window.event);
	    }
	    return toolkit.getEvent.caller.arguments[0];
	}
}

Posted: Sat Aug 19, 2006 7:48 pm
by alex.barylski
Not sure if it's directly useful, but that code will come in handy for reference...thanks dude :P

Secondly, I hate that javascript object literal syntax, it's so unclear and my IDE doesn't recognize functions that way :P

Seriously though, why do people do it that way? What is the point? I've read it's more efficient to use the traditional technique of mapping methods and members to the object...

Any idea about that? Would you care to execute a test on the differences for me? :)

Posted: Sun Aug 20, 2006 9:04 am
by Ollie Saunders
Seriously though, why do people do it that way? What is the point? I've read it's more efficient to use the traditional technique of mapping methods and members to the object...
I think its faster. What did you read?
I do it because it shows that the functions are contained within the object more clearly.
my IDE doesn't recognize functions that way
Well there's the real reason why you hate it :), get yourself a better IDE.

Posted: Sun Aug 20, 2006 10:18 am
by Chris Corbyn
By the way, if you have access to do it I'd certainly test pages in safari as well as the ons you tested that code in. Opera, FF, IE and Safari are pretty much the major browsers these days. I usually open my pages in Lynx too just to see how they look without any styling.

Posted: Sun Aug 20, 2006 10:51 am
by RobertGonzalez
<tad-off-topic>
Does anyone know a safari emulator or a way to run Safari on Windows? That would be so much easier than sending all of my designs to d11 for review :wink:
</tad-off-topic>

Posted: Sun Aug 20, 2006 11:11 pm
by feyd
Everah wrote:<tad-off-topic>
Does anyone know a safari emulator or a way to run Safari on Windows? That would be so much easier than sending all of my designs to d11 for review :wink:
</tad-off-topic>
Found this a moment ago on my travels across the infoporn.

http://www.webstandards.org/2006/08/09/ ... r-windows/

Posted: Sun Aug 20, 2006 11:14 pm
by RobertGonzalez
Thanks Feyd. I look over that in a little bit.