473,394 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 misunderstanding something... I was using
element.setAttribute 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.setAttribute('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.getElementById("pgallery");
galholder = document.createElement("div");
galholder.className = "galleries";
for ( i = 0; i < gallerylist.length; i++ )
{
nd = document.createElement("a");
nd.className = "media";
nd.style.cursor = "pointer";
addClick(nd, i);
text = document.createTextNode(gallerylist[i][1]);
nd.appendChild(text);
galholder.appendChild(nd);
}
obj.appendChild(galholder);
spacer = document.createElement("div");
spacer.className = "picspacer";
obj.appendChild(spacer);
}

Jul 23 '05 #1
3 1888
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 misunderstanding something... I was using
element.setAttribute 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.setAttribute('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.getElementById("pgallery");
galholder = document.createElement("div");
galholder.className = "galleries";
for ( i = 0; i < gallerylist.length; i++ )
{
nd = document.createElement("a");
nd.className = "media";
nd.style.cursor = "pointer";
A elements already have a default cursor of pointer.
addClick(nd, i);
text = document.createTextNode(gallerylist[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.appendChild(nd);
}
obj.appendChild(galholder);
spacer = document.createElement("div");
spacer.className = "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.getElementById("pgallery");
var galholder = document.createElement("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.createElement('A');
x.appendChild(document.createTextNode('blah'));
x.href = 'http://www.apple.com';
addClick( x );
document.getElementById('toMe').appendChild(x);
}
</script>

<div onclick="addA(this);">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.infosystems.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><title>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('Navigate 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>Apple
</a><br>
<a href="http://www.Google.com"
onclick="return doStuff(this)"><img
src="a.gif" alt="Go to Google"><br>Google
</a><br>
<a href="http://www.Yahoo.com"
onclick="return doStuff(this);"><img
src="a.gif" alt="Go to Yahoo"><br>Yahoo
<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
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...
7
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
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...
2
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...
3
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...
3
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...
8
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...
28
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...

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.