473,782 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic HTML cross-browser

I am brand-new to javascript, but after reading some tutorials online I
was able to make a dynamic HTML photo gallery in javascript. It works
fine in all browsers except IE6 (big surprise). I've been looking
around online for solutions, but the fixes I have seen don't seem to
work. I assume I am misunderstandin g something... I was using
element.setAttr ibute but have changed my code to avoid that. Here is an
example. IE6 displays the link text but doesn't do anything else--exact
same result I had by using element.setAttr ibute('name', 'value').

Any suggestions would be appreciated.
Thx,
Aaron

// scope workaround
function addClick(parent , index)
{
parent.onclick = function() { getThumbs(index ); };
}

// make a link for each gallery
function makeButtons()
{
obj = document.getEle mentById("pgall ery");
galholder = document.create Element("div");
galholder.class Name = "galleries" ;
for ( i = 0; i < gallerylist.len gth; i++ )
{
nd = document.create Element("a");
nd.className = "media";
nd.style.cursor = "pointer";
addClick(nd, i);
text = document.create TextNode(galler ylist[i][1]);
nd.appendChild( text);
galholder.appen dChild(nd);
}
obj.appendChild (galholder);
spacer = document.create Element("div");
spacer.classNam e = "picspacer" ;
obj.appendChild (spacer);
}

Jul 23 '05 #1
3 1909
Aaron Gervais wrote:
I am brand-new to javascript, but after reading some tutorials online I
was able to make a dynamic HTML photo gallery in javascript. It works
fine in all browsers except IE6 (big surprise). I've been looking
around online for solutions, but the fixes I have seen don't seem to
work. I assume I am misunderstandin g something... I was using
element.setAttr ibute but have changed my code to avoid that. Here is an
example. IE6 displays the link text but doesn't do anything else--exact
same result I had by using element.setAttr ibute('name', 'value').

Any suggestions would be appreciated.
Don't post code with tabs. Use 2 or 4 spaces for indents and manually
wrap code at about 70 characters to prevent auto-wrapping (which
introduces errors and makes assistance a chore).
Thx,
Aaron

// scope workaround
function addClick(parent , index)
{
parent.onclick = function() { getThumbs(index ); };
I think your problem is with getThumbs(). Change the onclick to
something trivial:

parent.onclick = function() { alert('Hey ' + index); return false; };

If that works, then your issue is with getThumbs(). Since the onclick
is on an A element, your function should return false to cancel
navigation (see below):

parent.onclick = function() {
getThumbs(index );
return false;
};
}

// make a link for each gallery
function makeButtons()
{
obj = document.getEle mentById("pgall ery");
galholder = document.create Element("div");
galholder.class Name = "galleries" ;
for ( i = 0; i < gallerylist.len gth; i++ )
{
nd = document.create Element("a");
nd.className = "media";
nd.style.cursor = "pointer";
A elements already have a default cursor of pointer.
addClick(nd, i);
text = document.create TextNode(galler ylist[i][1]);
nd.appendChild( text);
You should give your A an href value that links to the image so that
users without JavaScript can still see it. Have your onclick return
false to prevent those with JS enabled from following the link.
galholder.appen dChild(nd);
}
obj.appendChild (galholder);
spacer = document.create Element("div");
spacer.classNam e = "picspacer" ;
obj.appendChild (spacer);
Spacing should be done with CSS, not with 'spacer' elements. You are
also creating a heap of global variables which may get you into trouble,
especially with counters like 'i'. To keep variables local, declare
them inside functions using the 'var' keyword, e.g.:

var obj = document.getEle mentById("pgall ery");
var galholder = document.create Element("div");
}


Here's a small test:

<script type="text/javascript">
function addClick ( el ){
el.onclick = function() { alert('hi from blah'); return false;};
}
function addA ( el ) {
var x = document.create Element('A');
x.appendChild(d ocument.createT extNode('blah') );
x.href = 'http://www.apple.com';
addClick( x );
document.getEle mentById('toMe' ).appendChild(x );
}
</script>

<div onclick="addA(t his);">click me<br></div>
<div id="toMe"></div>


--
Rob
Jul 23 '05 #2
All I needed was "return false;". getThumbs() worked fine after that. I
don't quite understand why I need to put return false in there,
however... Thanks about the variable scope--I thought the opposite was
true. div.spacer is simply set to {clear:both} in the css file, and I
use it to prevent the floating thumbnails from starting on the same
line as the floating gallery links. If you can suggest a better
solution, I'm all ears.

Aaron

Jul 23 '05 #3
Aaron Gervais wrote:
All I needed was "return false;". getThumbs() worked fine after that. I
don't quite understand why I need to put return false in there,
It cancels nagivation via the href - IE has a few odd behavious with A
elements, I'll assume the lack of an href was causing an problem.
however... Thanks about the variable scope--I thought the opposite was
true. div.spacer is simply set to {clear:both} in the css file, and I
use it to prevent the floating thumbnails from starting on the same
line as the floating gallery links. If you can suggest a better
solution, I'm all ears.


Please quote what you are replying to and trim any excess.

The above is not really a javascript question, it should be asked at:

comp.infosystem s.www.authoring.stylesheets

Anyhow, there are a thousand ways of skinning a cat. I can't see your
markup or layout, so I have no idea what a potential fix may be. But
your page should work with CSS disabled, if you are dependent on spacer
divs as above, it isn't.

I'll take a guess that your links have a thumbnail above with text below
and are centered in some element. Try the following example, the
gallery div can be set to any width and if the body has 'text-align:
center;' it will float in the middle (unless there are competing
elements...). The thumbs and links float in the middle of the div.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html><head><ti tle>Show random matrix</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function doStuff( x ) {
if ( x.blur ) x.blur();
return confirm('Naviga te to ' + x.href + '?');
}
</script>

<style type="text/css">
body {
background-color: #000000;
color: gold;
}
#gallery {
margin-top: 0;
padding: 0;
text-align: center;
width: 10em;
}
#gallery img {
margin-top: 30px;
text-decoration: none;
border: 2px solid gold;
}

#gallery a {
color: gold;
font-style: italic;
text-decoration: none;
}
#gallery a:active {color: gold;}
#gallery a:visited {color: gold;}
#gallery a:hover {color: red;}

</style>
</head>
<body>
<div id="gallery">
<a href="http://www.apple.com"
onclick="return doStuff(this);" ><img
src="a.gif" alt="Go to Apple"><br>Appl e
</a><br>
<a href="http://www.Google.com"
onclick="return doStuff(this)"> <img
src="a.gif" alt="Go to Google"><br>Goo gle
</a><br>
<a href="http://www.Yahoo.com"
onclick="return doStuff(this);" ><img
src="a.gif" alt="Go to Yahoo"><br>Yaho o
<br></a>
</div>
</body></html>

--
Rob
Jul 23 '05 #4

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

Similar topics

1
7512
by: Tim Pascoe | last post by:
I am using the Dynamic Cross-Tab code supplied in an article from SQL Server Magazine (http://www.winnetmag.com/SQLServer/Article/ArticleID/15608/15608.html). I modified the script to generate a temp table inside the stored procedure, and then use this temp table as the source for the cross-tab. However, the problem seems to be that the dynamic SQL string generated by the script is longer than what can be stored in the @SQL variable. The...
7
8404
by: Michael C# | last post by:
Is it possible to create Dynamic SQL queries in MySQL, like in SQL Server? i.e., the EXECUTE command or sp_executesql stored procedure in SQL Server. TIA
16
1557
by: Phil Powell | last post by:
The customer made a wild request: they want on their admin panel a textarea that will display an existing resume. This textarea, however, must have a dynamic width, one that "fills the screen width of any sized screen". Sorry but I cannot fathom how to do this! <textarea name="resume" cols="108" rows="29" wrap="physical><?= $resume ?></textarea>
2
8855
by: klh | last post by:
We use DB2 Connect v 7.2 FP7 in Windows NT hitting a OS/390 DB2 v7.1 database. We have a Websphere (java) application that issues dynamic SQL. Most of the time when we issue dynamic SQL SELECT statements, like through a DB2 command window, the command will be processed using a package like SQLLF000 which uses an isolation level of Cursor Stability. However sometimes in the Websphere application when a dynamic SELECT statement is issued...
3
9643
by: JDPope | last post by:
I have a situation which I cannot get a good lead on how to resolve. One of the applications I support uses the Hibernate software to generate SQL. The app is JAVA with JDBC. In testing the users see no problems and think the app is running okay. I turned a database monitor on the app and see that the database is getting SQL return coes of -301 for a variety of database accesses (some times the same access works, okay other times -301)....
3
2673
by: Mukesh | last post by:
sir, i am developing a database, which will store the users profile both personal and professional which includes the address, telephone, gender and etc. in my main table i have created a column of xml data type. i was successful in inserting the static value inside my table.by following code:--- UPDATE docs
8
338
by: mfc | last post by:
Suppose I have a Cookie class and a Factory Class. There are many types of Cookies and maybe one or more Factories with a ProcessCookie Method. Suppose all the PutInBox method does is decide what colour box to put the cookie into. But since the colour of the box depends on whatever Factory is boxing them (Different branding etc) the PutInBox method can't be in the Cookie class and has to be in the Factory class. The problem is pretty soon...
28
3453
by: Peter Michaux | last post by:
Hi, I'm playing with dynamic script insertion to make a request to the server for a JavaScript file to be automatically run when it arrives in the browser. It works but... The page caching is too good. When I revisit the page or refresh the page, and then redo the script insertion, the browser doesn't even hit the server to check for a newer version of the JavaScript file. The same old script runs with each insertion.
3
2624
by: EnigmaticSource | last post by:
Currently, I am designing a site using CSS driven vertical menus, it works well in everything but MSIE. The menus seem to work well enough, except that they float behind the images, but above the text. The problem does not occur in Firefox, Konqueror, or Opera. I'm a bit lost for what the cause could be. Demonstration URL: http://delta.teamcenturion.com Thanks in advance for the help.
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9942
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6733
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4043
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 we have to send another system

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.