By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,183 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,183 IT Pros & Developers. It's quick & easy.

Script Problems (Speed & Compatibility)

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.