codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Cross Browser getElementById issues! Random Background Image  Archive Import (Andrew K) at 12:23 on Tuesday, July 01, 2003
 

Hello, I hope someone can help!!

I have some code to produce a random background image which is pulled in to the TD tag using an ID="bgimage1" statement - this works great on IE, however I need it to work on Netscape 4!

Is this because of the ID or the getElementById?

This is the JS statement:

document.getElementById(`bgimage1`).style.background = `url(` + image1[titleIndex] + `)`;

image1[titleIndex] is the random part

Please help!

Thanks

Andrew

  Re: Cross Browser getElementById issues! Random Background Image  Archive Import (James Laugesen) at 13:02 on Tuesday, July 29, 2003
 

Hi Andrew.
Here some handy code you can use to reference an object safely in any browser.

Rather than using document.getElementById(`id`), document.all[`id`], etc. You can use findDOM(`id`, 0) or findDOM(`id`, 1).

findDOM(`object`), 0) is like document.object
and findDOM(`object`, 1) is like document.object.style


The function just uses the supported DOM type for the browser and returns the object reference; getElementById, Layers or All. Browser details are first stored in global variables so you can use them elsewhere.

You should put the follow code in a .JS file so you can easily move it around and include it into pages.

Hope it helps you and anyone else out.

Cheers,
James

  Re: Cross Browser getElementById issues! Random Background Image  Archive Import (James Laugesen) at 13:07 on Tuesday, July 29, 2003
 

Here it is... (Just trying to deal with the dodgy Codetoad.com forum.).
Remove the remove the /`s from any "pa//rseInt", stupid forum.

var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if(document.getElementById)
{
isID = 1;
isDHTML = 1;
}
else
{
if(document.all)
{
isAll = 1;
isDHTML = 1;
}
else
{
browserVersion = pa//rseInt(navigator.appVersion);
if((navigator.appName.indexOf(`Netscape`) != -1) && (browserVersion == 4))
{
isLayers = 1;
isDHTML = 1;
}
}
}

function findDOM(objectID, withStyle)
{
if (withStyle == 1)
{
if (isID)
{
return (document.getElementById(objectID).style);
}
else
{
if (isAll)
{
return (document.all[objectID].style);
}
else
{
if (isLayers)
{
return (document.layers[objectID]);
}
}
}
}
else
{
if (isID)
{
return (document.getElementById(objectID));
}
else
{
if (isAll)
{
return (document.all[objectID]);
}
else
{
if (isLayers)
{
return (document.layers[objectID]);
}
}
}
}
}

  Re: Cross Browser getElementById issues! Random Background Image  Archive Import (Andrew K) at 05:55 on Thursday, July 31, 2003
 

Thanks James

Thats extremely helpful

Andrew

  Re: Cross Browser getElementById issues! Random Background Image  Archive Import (James Laugesen) at 13:44 on Thursday, July 31, 2003
 

No problem Andrew, glad I could help.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  java programming help
•  java programming help
•  Re: hi there! first post
•  Reference a <TABLE> HTML Cell in VBA
•  Re: datagrid linkbutton will not fire Postback at random times
•  Re: Running a Javascript from VBA.
•  Re: how to extract search engine results
•  Re: APIs to convert file format
•  Re: Best collection type for this project?


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005