470,644 Members | 1,202 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,644 developers. It's quick & easy.

Script Problems (Speed & Compatibility)

Greetings fellow coders. Please check this page for a code which
rearranges chess cells:
http://s95005072.onlinehome.us/blog/Chess/chess.htm

There are 2 problems:
1. It takes quite a bit for the function to run each time. I don't know
how to speed it up further.
2. The function runs twice on mozilla browsers for some reason.

Any help is greatly appreciated. And hold your flames, this is my first
usable JS script.
Jul 23 '05 #1
2 1120
An idea just came to me. Maybe problem #2 is because after every time I
click on the link, the onload event is fired. If I'm right, how do I
avoid it?
Jul 23 '05 #2
Not sure what you mean by slow. Seemed to work really fast with IE 6.0.

Anyway in general string concatenation can be slow and before IE 6.0 setting
the innerHTML property was pretty slow and I think is still slow for Mozilla
compared to using the DOM methods. But I may be out of date with this.

First I would recommend altering the code to use the DOM methods for element
creatation rather than using innerHTML. But if you want to use innerHTML the
faster way to perform string concatenation is to add the strings to an Array
and then perform an Array.join();

so

[snip]

var content = new String; // stores the table for output

content = "<table border='0' width='432' height='432' cellspacing='0'
cellpadding='0'>";
// first border row
content += "<tr height='9'>";

[/snip]

would become

var content = new Array();

content.push("<table border='0' width='432' height='432' cellspacing='0'
cellpadding='0'>");
// first border row
content.push("<tr height='9'>");
..
..
..
showContentObj.innerHTML=content.join();

"Adelson Anton" <ad*****@mail.ru> wrote in message
news:40******@duster.adelaide.on.net...
Greetings fellow coders. Please check this page for a code which
rearranges chess cells:
http://s95005072.onlinehome.us/blog/Chess/chess.htm

There are 2 problems:
1. It takes quite a bit for the function to run each time. I don't know
how to speed it up further.
2. The function runs twice on mozilla browsers for some reason.

Any help is greatly appreciated. And hold your flames, this is my first
usable JS script.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Phil Powell | last post: by
reply views Thread by Michael Fork | last post: by
11 posts views Thread by Jonny | last post: by
30 posts views Thread by Toni Mcintyre | last post: by
13 posts views Thread by Yousuf Khan | last post: by
3 posts views Thread by Razvan | last post: by
17 posts views Thread by PJ | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.