473,473 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Javascript toggles div visibility, img elements dissappear

Hi Folks,

I am having a strange Javascript issue. I have a div that I show and
hide by clicking on an image link, and all images within the div do not
show up in IE. FireFox does not give me this problem. Also, under IE,
when I expand the div and adjust the font size with <control + mouse
wheel> the images show up.

When I do not set the div's style.position at all in the javascript,
this problem does not occur. I am making a tree, however, so that is
not an option since the elements end up on top of each other.

The code...
<html>
<head>
<title>Expand Tree</title>
<script LANGUAGE="JavaScript">
function splodeDiv(divRef, imgRef){
var theDiv = document.getElementById(divRef);
var theImg = document.getElementById(imgRef);
var divState = theDiv.style.visibility == "hidden";
theDiv.style.visibility = divState ? "visible" : "hidden";
theDiv.style.position = divState ? "relative" : "absolute";
theImg.src = divState ? "minus.gif" : "plus.gif";
}

function load(){
var allImgs = document.getElementsByTagName('img');
for(var i = 0; i < allImgs.length; i++){
if(allImgs[i].id.search('expandRetract' != -1)){
allImgs[i].src = "minus.gif";
}
}
var allDivs = document.getElementsByTagName('div');
for(var i = 0; i < allDivs.length; i++){
if(allDivs[i].id.search('folderGroup' != -1)){
allDivs[i].style.visibility = "visible";
allDivs[i].style.position = "relative";
}
}
}

</script>
</head>
<body onload="javascript:load();">

<a href="javascript:splodeDiv('folder Group1', 'expandRetract1');"><img
id="expandRetract1" src="minus.gif" border="0"></a>
<div id="folder Group1">
Howdy!
<img src="minus.gif">
<img src="minus.gif">
<img src="minus.gif">
</div>

</body>
</html>

Any help on this would be a life saver. I am past a deadline for a
demo!

Dan Wilson

Dec 6 '05 #1
3 3303
dwilson wrote:
I am having a strange Javascript issue. I have a div that
I show and hide by clicking on an image link, and all
images within the div do not show up in IE. FireFox does
not give me this problem. Also, under <snip>

So, in IE only, the user clicking on something causes the browser to
stop working in the way it previously had. Those are the symptoms of the
use of a javascript pseudo-protocol HREF.
<a href="javascript:splodeDiv('folder Group1',
'expandRetract1');"> ... <snip>

And there it is. IE treats the activation of a javascript
pseudo-protocol HREF as navigation, and when used the browser goes into
a 'waiting state' pending the arrival of a replacement for the content.
In this state many previously available browser facilities are
withdrawn, including GIF animation and image swapping.

The normal strategy for dealing with this issue is to never use a
javascript pseudo-protocol HREF that will not result in the replacement
of the contents of the current page (so never to execute a function for
its side effect).

Usually the same effect as a javascript pseudo-protocol HREF can be
achieved (without the detrimental consequences in IE) with a suitably
default action cancelling intrinsic event handler. An onclick handlers
are the usual replacement. So, something like:-

<a href="someURL"
onclick="splodeDiv('folder Group1','expandRetract1');return false;" ... </a>


Where - someURL - is the url of a resource that should never be visited
while javascript is available/enabled because the click event is
cancelled by its handler returning false, and so may act as an
alternative to the scripted action, or apologise to the user for the
needless creation of a javascript dependent web site.

Richard.
Dec 6 '05 #2
So I have tried your suggestion, and even went so far as to remove the
anchor tag and use the onclick event directly on the img itself. I am
getting the same behavior, and not only with images but with a table as
well. I guess my question is how can I call this javascript without the
browser being in a state that will not reflect/redraw these elements?
The code...

<html>
<head>
<title>Expand Tree</title>
<script LANGUAGE="JavaScript">
function splodeDiv(divRef, imgRef){
var theDiv = document.getElementById(divRef);
var theImg = document.getElementById(imgRef);
var divState = theDiv.style.visibility == "hidden";
theDiv.style.visibility = divState ? "visible" : "hidden";
theDiv.style.position = divState ? "relative" : "absolute";
theImg.src = divState ? "minus.gif" : "plus.gif";
}

function load(){
var allImgs = document.getElementsByTagName('img');
for(var i = 0; i < allImgs.length; i++){
if(allImgs[i].id.search('expandRetract' != -1)){
allImgs[i].src = "minus.gif";
}
}
var allDivs = document.getElementsByTagName('div');
for(var i = 0; i < allDivs.length; i++){
if(allDivs[i].id.search('folderGroup' != -1)){
allDivs[i].style.visibility = "visible";
allDivs[i].style.position = "relative";
}
}
}

</script>
</head>
<body onload="javascript:load();">

<img id="expandRetract1" src="minus.gif" onclick="splodeDiv('folder
Group1', 'expandRetract1');return false;">
<div id="folder Group1">
Howdy!
<img src="minus.gif">
<table border="1">
<tr>
<td>
in the table
</td>
</tr>
</table>
</div>

</body>
</html>

Thanks.

Dan Wilson

Dec 7 '05 #3
dwilson wrote:
<snip>
function load(){
var allImgs = document.getElementsByTagName('img');
for(var i = 0; i < allImgs.length; i++){
if(allImgs[i].id.search('expandRetract' != -1)){
This expression is wrong. The argument being passed to the search method
is - 'expandRetract' != -1 -, and its result is boolean. That boolean
result will be type-converted into a string and then that string into a
regular expression, either /true/ or /false/ (most likely /false/).
Those regular expressions look like they will not match the IDs and so
the search expression will return -1, and -1 is true. So the block of
the if statement will be executed on every image on the page, making all
of their SRCs "minus.gif".

The line should probably be:-

if(allImgs[i].id.search('expandRetract') != -1){
allImgs[i].src = "minus.gif";
}
}
var allDivs = document.getElementsByTagName('div');
for(var i = 0; i < allDivs.length; i++){
if(allDivs[i].id.search('folderGroup' != -1)){
Much the same goes for this - if - expression, and every DIV on the page
will be rendered invisible.

<snip> <div id="folder Group1">

<snip>

IDs are not allowed to contain spaces.

The extent to which the above errors will influence the outcome should
not differ significantly between IE and Firefox (or any other browser
for that matter) so they do not explain the symptoms described.

Richard.
Dec 7 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
4
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button...
1
by: Oliver Hoehle | last post by:
Hello! This ist the source-code for an editable combobox implemented with HTML,CSS and Javascript. I have tested it with IE and Mozilla. But I don't know, if it will work in other browsers...
8
by: bradwiseathome | last post by:
I have code that works in IE 6 but does not work in FireFox 1.0.2, how can I change it so it works in both browsers? <html> <head> <script language="JavaScript" type="text/JavaScript">...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
14
by: earl.robb | last post by:
Please excuse me If I am posting to the wrong group. I was recommended here from one of the Database groups I regularly track. I have a small script that loads a table with some elements...
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
13
by: windsorben | last post by:
I have some javascript that checks whether or not an answer is correct. It was working fine when the question was asked with text but now that I'm asking the question with audio, the javascript no...
0
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, imagine this for a moment if you will: i have a row in a gridview that when it is in edit mode there is a column that contains a dropdownlist and 2nd column that contains a user control....
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.