Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Including the cross-browser objects into a page

February 1st 1998

If a Web page needs to provide cross-browser functionality, both source code files need to be included within the page. If the page only needs to support one browser or another, only one file needs to be included. Why use a cross-browser object for a browser-specific page? With the use of cross-browser objects, an added advantage is that if the browser alters its DHTML implementation I need only make the change within the cross-browser code and not in all of the applications using the DHTML functionality. With all of the efforts currently underway at the W3C on the Document Object Model standard (accessible from the resource section), this centralization of the browser-specific functionality is a good idea even if the site is not creating cross-browser objects.

For now, the technique to include both browsers' objects into a page is:

<SCRIPT src="ns4_obj.js" language="javascript1.2">
</SCRIPT>

<SCRIPT src="ie4_obj.js" language="jscript">
</SCRIPT>

This technique includes JavaScript source into a page. The first source code file included is the Navigator source code file, with a language of "javascript1.2". The second is the IE source code file, with a language of "jscript". As the objects and object instantiation routines are named the same, what keeps each browser from picking up the wrong code?

First, Navigator will not pick up code from a scripting specification it does not process, so it will not pick up the "jscript" source code. Now, IE 4.x does process JavaScript 1.2 as well as JScript, and actually loads both files. However, if both files contains functions with the same name, IE 4.x defaults to using the functions in the scripting block that is included last in the page. As the IE 4.x cross-browser object source code file is positioned after the Navigator specific source code file, IE 4.x picks up the functions from the appropriate file. Based on this, it is essential that the order taken for including these files be followed.

Once the script files are included into the page, the cross-browser objects are instantiated with a call to wdvlCreateObjects. This function must be called after all the elements on the page have been loaded to the browser, so I usually call this function within the onLoad event of the page:

<BODY onload="wdvlCreateObjects()">

That's all it takes to create the cross-browser objects. Next up, time to create a test case to make sure the objects have been instantiated correctly.

Creating Cross-Browser Objects
Creating Cross-Browser DHTML Objects
Using the cross-browser objects...A test page



Up to => Home / Authoring / DHTML / CB / Objects




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers