Cross browser charts???

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Cross browser charts???

Post 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 :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Blew right by that one...guess I'll giver' a second look :P
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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];
	}
}
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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? :)
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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/
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Thanks Feyd. I look over that in a little bit.
Post Reply