Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


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
International

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


Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

Adding objChangeSource to the Cross-Browser Objects

April 1, 1998

Adding objChangeSource to the Cross-Browser Objects

To add a new method to the cross-browser objects is no more complicated than adding a new property to the object constructor that references the method function pointer. A function pointer is the same as the name of the function, without the parameters and without the "function" specifier. The code to extend the Navigator cross-browser object is:

this.objChangeSource = objChangeSource; // add to object constructor

function objChangeSource(sourcefile, width) {
   this.obj.load(sourcefile, width);
}

The first line of the code is added to the object constructor function and the new method is added at the bottom of the file, though it can be added anywhere within the cross-browser JavaScript source file. The Netscape layer function load is used to load the new source. The reason load is used is that it allows you to specify a width for the container, which then forces the contents to wrap to fit this width.

The addition of the function to the IE cross-browser object is not quite as simple. In part 1when the object was created it was created to point to the object's style object, rather than directly to the object passed to it. I also stated in this article that this would need to be changed for the part 3 code. The reason for this change is that the "src" attribute used to load the new content into the Web page is not referenced directly from the style object, but from the object itself. So, based on this the object needs to be changed and each of the functions that reference the object need to be changed. The following code block shows the change to the object constructor, one of the existing functions, objGetTop, and the new object method:

// object constructor change
function wdvlNewObject(obj) {
	this.obj = obj;   // rather than this.obj = obj.style

// element's top position
function objGetTop () {
	return this.obj.style.pixelTop;
}

function objChangeSource(sourcefile,width) {
  var name = this.name;
  this.obj.src = sourcefile;
}

The reason that I deliberately built-in a necessary change into the IE cross-browser object is to demonstrate that the object can be changed, significantly, yet still work with existing as well as new pages. This demonstrates the real power of using JavaScript objects to handle browser, as well as browser version, differences.

Notice that the IE version of objChangeSource does not use the width parameter. As the parameter is necessary for the Netscape version of the code, and the same method is called for both browsers, it is necessary to duplicate the width parameter for the IE specific function. It is then just ignored within the IE code.

The functions to change the inset source are created next.

Cross-Browser Objects: Creating a "load on demand" Web Page
Cross-Browser Objects: Creating a "load on demand" Web Page
Adding the Change Page Functionality



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




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, Reprints, & Permissions, Privacy Policy.

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