473,396 Members | 1,866 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,396 software developers and data experts.

why does the script crash IE?

First of all I only have IE for testing.

Ok. I have a script that is supposed to show, not evaluate, the
indefinite integral of something. When I run the script it just craches
IE. I have tried to get all the obvious bugs out... Um... The script is
at: http://ali.freezope.org/idf test and what it is supposed to show is
at: http://ali.freezope.org/idf result

Jul 23 '05 #1
15 2117
greenflame wrote:
First of all I only have IE for testing.

Ok. I have a script that is supposed to show, not evaluate, the
indefinite integral of something. When I run the script it just craches
IE. I have tried to get all the obvious bugs out... Um... The script is
at: http://ali.freezope.org/idf test and what it is supposed to show is
at: http://ali.freezope.org/idf result


Post URL's thusly:

<URL:http://ali.freezope.org/idf result>

especially if you have spaces in the URL.

You should probably warn users explicitly to turn of JavaScript before
they click on the link if JavaScript is the cause of the 'crash'. The
browser doesn't crash, you send it into a never-ending loop in your
indefiniteintegral() function.
function indefiniteintegral(input,mainline,differential) {
var dummy;
var output = copy2darr(input);
dummy = output.unshift(new Array(output[0].length));
dummy = output.push(new Array(output[0].length));
Why assign some number to the variable 'dummy', then overwrite it, then
do so again below?

for (var i=0;i<output.length;i++) {
-----------------^^^^^^^^^^^^^

Here the value of output.length is evaluated every loop. This is slow
and, in this case, creates an infinite loop. Use a variable to store
the value of output.length (it will also slightly speed up your loop):

for (var i=0, len=output.length; i<len; i++) {
if (i == 0) {
dummy = output[i].unshift("<font face=symbol>ó</font>");
dummy = output[i].push(" ");
Don't use such outdated HTML - use span elements, preferably using DOM
rather than document.write. And create a class so you don't have
numerous style declarations:

dummy = output[i].unshift('<span style="font-family:symbol">'
+ 'ó</span>');

or, if using CSS and classes, have a style declaration in the head:

<style type="text/css">
.sym { font-family: symbol; }

then:

dummy = output[i].unshift('<span class="sym"> + 'ó</span>');
} else if (i == mainline) {
dummy = output[i].unshift("<font face=symbol>ô</font>");
dummy = output[i].push(differential);
} else if (i == output.length-1) {
dummy = output.unshift("<font face=cymbol>õ</font>");
--------------^^^^^^^^^

Here you are putting stuff into output and making it longer while your
for loop is trying to catch up - it never will . You also have a fault
in the depreciated font tag - I think you want 'symbol', not 'cymbol'.
dummy = output[i].unshift("<font face=cymbol>õ</font>");
dummy = output[i].push(" ");
} else {
dummy = output.unshift("<font face=symbol>ô</font>");
--------------^^^^^^^^^

And the same here.

dummy = output[i].push(" ");
}
}
return output;
}
Fixing the above mostly fixes your output, but not entirely for me.
Other comments:

* In your copy2darr() function, the line:

var output = new Array(input.length);

can be replaced with:

var output = [];

* The depreciated 'font' element at the start of your file should be
replaced with either a span, pre or code element:

<font face="courier new"> ... </font> becomes:

<pre> ... </pre>

* All of those lines with:

if (input == "del") {output = "<font face=symbol>Ñ</font>"}

can be replaced by creating the following variables at the start of the
function:

var fOn = '<font face="symbol">'
var fOf = '</font>'

then use:

if (input == "del") {output = fOn + 'Ñ' + fOf }
You really should be using span elements with CSS, but I don't know the
appropriate font-family to replace symbol - try in:

comp.infosystems.www.authoring.stylesheets
--
Rob
Jul 23 '05 #2
RobG wrote:
greenflame wrote:
[...]
Other comments:


Modify your convert() function as follows:

function convert( inVal ) {
var sOn = '<font face="symbol">'
var sOf = '</font>'

if (inVal == undefined){ return "&nbsp;" }
if (inVal == "hyf") {return "—" }
if (inVal == "vA" ) {return "<b>A</b>" }
...
...
...
if (inVal == "]b") {return sOn + 'û' + sOf}
}

Your sequential if's will test every single 'if' every single time.
Modifying the script as above will return to the calling function as
soon as the match is found.

It is also pointless to copy 'input' to 'output' when 'output' is not
modified in any way - it's just used in the test.
--
Rob
Jul 23 '05 #3
RobG <rg***@iinet.net.auau> writes:
Post URL's thusly: <URL:http://ali.freezope.org/idf result>
Preferably as a valid URL (without spaces):
<URL:http://ali.freezope.org/idf%20result>
<font face=symbol>ô</font>


While this is the correct form of what the original poster is trying
to do, it is still not the correct way to do it.

The entity ô represents the Unicode character with code point
244, i.e., ô (also known as &ocirc;, an o with a circumflex accent).
It is then attempted rendered in the font "Symbol". The problem is
that that font does not contain a glyph for o-circumflex.

Earlier, when Unicode was not as widespread and everything worked
using 8-bit encodings, the glyphs of the Symbol font was mapped to
8-bit values, so rendering the byte 244 in that font would give
the 244th entry of the font file. Those days are over. Modern
font-aware programs, browsers included, will not render ô
in the symbol font, but will fall back on the next font specified
in a font tag, or the browser's default font.

There is no Unicode codepoint representing "the top third of an
integral sign", because Unicode represents entire symbols only.
The integral sign can be written as &#8747 or &#int;. I recommend
something like:

<p style="line-height:300%">
<span style="font-size:300%;vertical-align:middle;">∫</span>x dx
</p>

The exact vertical alignment is a little hard to get right across
browsers.
(read more about symbols in HTML here:
<URL:http://www.w3.org/TR/WD-entities-961125>)

The encoding of the page is not specified by either the page itself or
the server, so the browser must guess. I can see that my browser
guesses "windows-1252". You should specifiy an encoding, preferably
from the server, but if not, as an element of the page:
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-15">

Follow-up set to comp.infosystems.www.authoring.html, since this
is about HTML, not javascript.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #4
So you think that every where I have:

"<font face=symbol>" +...+"</font>"

I should replace it with:

"<span class=sym>+...+"</span>"

while puting:

<style type="text/css">
.sym { font-family: symbol; }
</style>

in the <head>? And the same idea for when I use:

'<font face="courier new">'+...+'</font>'?

Or do You think I should use the sOn and sOf idea?

Also making an undefined array (eventhough I know its length) and
filling it is faster/better than making an array of defined length and
filling it? If so then how?

Also you said to use DOM instead of document.write. How do I do this?
You also suggest using span elements with CSS. How does this work?

Jul 23 '05 #5
greenflame wrote:
So you think that every where I have:

"<font face=symbol>" +...+"</font>"

I should replace it with:

"<span class=sym>+...+"</span>"

while puting:

<style type="text/css">
.sym { font-family: symbol; }
</style>

in the <head>? And the same idea for when I use:

'<font face="courier new">'+...+'</font>'?

Or do You think I should use the sOn and sOf idea?
I think you should replace the <font...> stuff with spans.

One way of doing that is to simply replace the <font...> strings in your
code with <span...> strings.

A more efficient way of doing it is to store the <span...> string in a
variable with a short name (e.g. sOn, sOf) and use the variable in place
of the string in your code.

Also making an undefined array (eventhough I know its length) and
filling it is faster/better than making an array of defined length and
filling it? If so then how?
Better? Yes.

Faster? For all practical purposes, no. There have been recent
discussions about different ways to create arrays and about setting a
length without filling all (or any) values - 'sparse' arrays.

Consider:

var a = []; - and - var a = new Array();

The first method is less code with fewer keystrokes so less chance of an
error. The cleaner code is easier to read and debug, and when compared
with your:

var a = new Array( x[0].length );

the difference is further highlighted. The two are essentially the same
(the time taken for the extra lookup for x[0].length is insignificant as
a one-of event). The only difference is that an array declared with a
length will have one, whereas one declared without a length won't -
which is of no practical value in your case.

Use var a = [] wherever possible and reasonable, which is nearly always.

Also you said to use DOM instead of document.write. How do I do this?
You also suggest using span elements with CSS. How does this work?


Here is a link to a site about using HTML for equations. It also has
some good links and tables with character entities that you'll likely
want to use.

<URL:http://www.myphysicslab.com/web_math.html>

I think you need to create functions that output various objects - a
matrixOutput function could take a matrix as input and generate the
required DOM objects. Other functions could display one and two line
(e.g. 2x+4 / 3y+3) equations. Then extend it to integrals, sums, etc.

Below is my version of a showMatrix() function. The random array
generator just truncates decimals, so if 'max' is set to 10, the biggest
number is 9 and smallest is -9 (max=100 gives -99 to +99, etc.).

It's just an example, it does no feature detection, it just assumes
support for getElementById, createElement and style. It also assumes
the matrix is rectangular (which includes square).

It doesn't validate input from the form when generating the matrix - the
script in the form button should probably be a separate function that
does appropriate validation, but hey, waddayawant fer free! :-)

Tested in Firefox and IE.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>Show random matrix</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">

// Array of n +ve & -ve integers of less than max value
function genRandomArray ( n, max ) {
var x = [];
while ( n-- ) {
x[n] = ( (Math.random()-0.5)*2*max ) | 0;
}
return x;
}

// Matrix of r arrays using genRandomArray( c, max )
function genRandomMatrix ( r, c, max ) {
var i, X = [];
while ( r-- ) {
X[r] = genRandomArray( c, max );
}
return X;
}

// Show m in a table inside element with id el
function showMatrix( m, el ) {
var el = document.getElementById(el);
var oT = document.createElement('table');
var oTB = document.createElement('tbody');
var i, j, r=m.length, c=m[0].length;
var oTR, oTD;
for ( i=0; i<r; i++ ){
oTR = document.createElement('tr');
j = c;
for ( j=0; j<c; j++ ){
oTD = document.createElement('td');
oTD.appendChild( document.createTextNode( m[i][j]) );
oTR.appendChild( oTD );
}
oTB.appendChild(oTR);
}
oT.appendChild(oTB);
el.appendChild(oT);
}

// Removes all children of element with id el
function clearContent( el ) {
el = document.getElementById( el );
while ( el && el.childNodes.length ) {
el.removeChild( el.firstChild );
}
}

</script>
<style type="text/css">
#mDiv { font-family: courier; font-size: 90%;}
#mDiv table {
border-left: 2px solid black;
border-right: 2px solid black;
border-collapse: collapse;
padding: 0; margin: 0;
}
#mDiv td {
text-align: right;
padding: 0 2ex 0 1ex;
white-space: nowrap;
}
</style>
</head><body>

<form action="">
<table><tr>
<td>rows:<input type="text" name="rows" size="3" value="4" ></td>
<td>cols:<input type="text" name="cols" size="3" value="4" ></td>
<td>max:<input type="text" name="max" size="3" value="10"></td>
<td><input type="button" value="Show random matrix" onclick="
clearContent( 'mDiv' );
var f = this.form;
var r = f.rows.value;
var c = f.cols.value;
var m = f.max.value;
showMatrix( genRandomMatrix( r, c, m), 'mDiv' );
">&nbsp;<input type="reset" onclick="
clearContent( 'mDiv' );
"></td>
</tr><tr>
<td colspan="4"><div id="mDiv"></div></td>
</tr></table>
</form>

</body></html>
--
Rob
Jul 23 '05 #6
JRS: In article <dd******************@news.optus.net.au>, dated Thu, 14
Jul 2005 07:10:01, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.auau> posted :

// Array of n +ve & -ve integers of less than max value
function genRandomArray ( n, max ) {
var x = [];
while ( n-- ) {
x[n] = ( (Math.random()-0.5)*2*max ) | 0;
}
return x;
}


While ISTM that does what it says, the middle value (zero) is about
twice as common as any of the others; ISTM worth noting, lest otherwise
be assumed. Try

A = genRandomArray(2000, 4)
B = [0,0,0,0,0,0,0,0,0]
for (J in A) B[A[J]+4]++
B // result.

It might be better to use the FAQ method with an argument of (?) 2*max-1
and subtract (?) max-1, if an even distribution is desired.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7
Umm.... ok I will do some work on the suggestions. Also I cant seem to
be able to star this thread. How do I get to do this? (I am using
Google Groups Beta)

Jul 23 '05 #8
Dr John Stockton wrote:
JRS: In article <dd******************@news.optus.net.au>, dated Thu, 14
Jul 2005 07:10:01, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.auau> posted :
// Array of n +ve & -ve integers of less than max value
function genRandomArray ( n, max ) {
var x = [];
while ( n-- ) {
x[n] = ( (Math.random()-0.5)*2*max ) | 0;
}
return x;
}

While ISTM that does what it says, the middle value (zero) is about
twice as common as any of the others; ISTM worth noting, lest otherwise
be assumed. Try

A = genRandomArray(2000, 4)
B = [0,0,0,0,0,0,0,0,0]
for (J in A) B[A[J]+4]++
B // result.

It might be better to use the FAQ method with an argument of (?) 2*max-1
and subtract (?) max-1, if an even distribution is desired.


Yes, my algorithm was quick 'n dirty, I didn't realise that it was not
evenly distributed. The one I've settled on is:

x[n] = ((Math.random()*(2*max+1)) | 0 ) - max;

Provides a distribution from -max to +max inclusive that should be
about as random as Math.random().

Values must be truncated before 'shifting', otherwise all values
between -1 and +1 become zero, doubling its representation.

var A = genRandomArray( num, max )
var B = [], i = max*2+1;
while(i--){B[i]=0;}
for (J in A) B[A[J]+max]++;
B; // result

:-)

--
Rob
Jul 23 '05 #9
So using the DOM method I must use a table? Also it seems like each
'tag' is now like a object. Is this right? Also I dont see how this is
any better than document.write().

Jul 23 '05 #10
greenflame wrote:
So using the DOM method I must use a table?
No, I chose to use a table as it's a convenient element to use for
displaying a matrix. You could do it as a bunch of DIVs or maybe
mono-spaced text with padding, but that's too hard as far as I'm
concerned - using at table it's a snap.
Also it seems like each 'tag' is now like a object. Is this right?
Tags exist only in the source HTML. When your browser parses HTML, each
'tag' is turned into an element, which behaves like an object. The
elements make up the Document Object Model - DOM.

You can consider the HTML as set of plans for making a document. When
the HTML is read by a browser, it builds elements based on the HTML's
instructions. The browser could be fed any document language that it
understands (say XML, Postscript, SGML) to build a document from.

The idea of using DOM is that you can manipulate the document without
regard for the underlying markup language. Since most browsers only
understand HTML, many programmers use document.write or innerHTML, but
they are limited.
Also I dont see how this is any better than document.write().


DOM is language and platform neutral. You don't have to worry about
language semantics - have you got matched tags? Are they properly
nested? Do you have end tags where needed? etc.

Using document.write anytime after the document has finished loading
replaces the entire content of the document every time you use it.

Your code so far is based on doing things as the document loads, but
eventually you'll want to do things at other times and not destroy your
document content in the process. Try replicating the sample page I
provided using document.write.

As you are manipulating tables, your options with innerHTML are reduced
as IE won't let you replace part of a table with innerHTML, only the
entire table or the content of a cell. It's behaviour is also
inconsistent across browsers for different element types - it has no
public specification so knowing who is right and who is wrong is moot.

And you still have the issue of generating properly formed HTML.

So use DOM.
--
Rob
Jul 23 '05 #11
RobG wrote:
[...]

DOM is language and platform neutral. You don't have to worry about
language semantics - have you got matched tags? Are they properly
nested? Do you have end tags where needed? etc.


Just thought I'd better point out that you don't have to worry about tag
nesting but you do have to worry about element nesting. e.g.:

<p><span style="font-weight: bold;">here is some text</p></span>

The above is invalid HTML 4 (though most browsers will tolerate it).
Using DOM, it can't happen but using document.write or innerHTML it can.

Using DOM it is possible to create invalid document structure - say
create a div and put it inside a span, even though block elements aren't
allowed inside inline elements.
[...]
--
Rob
Jul 23 '05 #12
OK. So do you know of any websites (for beginners) I can goto to learn
about using DOM?

Jul 23 '05 #13
greenflame wrote:
OK. So do you know of any websites (for beginners) I can goto to learn
about using DOM?


A reasonable place to start:

<URL:http://www.w3schools.com/>

or

<URL:http://www.w3schools.com/htmldom/default.asp>

It's a bit old and IE centric, but a useful introduction. Once you get
going, use this group's FAQ and searches through archives (sort the
results by date), you'd be amazed at what others have already written
for you.

:-)

--
Rob
Jul 23 '05 #14
I will give it ago. Thanks. :)

Jul 23 '05 #15
So I am trying to implement the following in DOM:

document.write("<div class='math'>"+str+"</div>");

I was wondering if the following would do it:

M = createElement('div');
M.class = "math";
M.appendChild(document.createTextNode(str));

If not, then what will?

Jul 23 '05 #16

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

Similar topics

2
by: sivignon | last post by:
Hi, I'm writing a php script which deals with 3 ORACLE databases. This script is launch by a script shell on an linux machine like this : /../php/bin/php ./MySript.php (PHP 4.3.3) My script...
6
by: PIII450 | last post by:
Hi all, I have a system running IIS en Apache. It is also running ASP and PHP. Why would <% Dim obj1 Dim var1
4
by: Lee Marsh | last post by:
Okay, I posted this over at alt.php, but got nil response, so I'm posting it hear again in hopes of getting a response. Sorry to anyone reading this twice: Okay...so on my website, where people...
2
by: MV | last post by:
How do I check if a browser supports an image using style before writing it with document.write? document.write("<img id='picture1' src='a.gif' alt='blah' style='blah'>"); NN4 and Opera 6 throw...
6
by: Christopher Benson-Manica | last post by:
Is Firefox 1.0.1 within its rights to crash when presented with the following script? <html> <head> <script> var foo="foo"; window.onerror=function( msg, url, line ) { switch( msg ) {...
6
by: VK | last post by:
I'm using window.open method in my script to open poup window. Recently Internet Explorer users reported that the script crashes on their machine with different runtime errors. See the bug:...
34
by: NewToCPP | last post by:
Hi, Why does a C/C++ programs crash? When there is access to a null pointer or some thing like that programs crash, but why do they crash? Thanks.
1
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
3
by: David | last post by:
On Sun, May 4, 2008 at 4:43 AM, lev <levlozhkin@gmail.comwrote: Hi, I started tidying up the script a bit, but there are some parts I don't understand or look buggy. So I'm forwarding you 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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...

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.