Hello,
I am querying the JavaScript community to learn if
others are having problems with Safari[1] and JavaScript
arrays:
myImages = [
"images/image0.jpg",
"images/image1.jpg",
"images/image2.jpg",
];
then referenced like this:
document.images[1].src = myImages[1];
Is this a known bug with Safari? Broken arrays?
(BTW the above works in every major browser's
recent version; those I have tried)
I can write a string literal into the src property:
document.images[1].src = "images/image1.jpg";
and achieve image replacement, but not when the string
literal is referenced from an array.
What gives? Am I doing something Really Stupid (TM)?
Thanks in advance for advice.
Cheers,
DK
[1] Referring to Safari version 1.0.1 12 2536
> I am querying the JavaScript community to learn if others are having problems with Safari[1] and JavaScript arrays:
myImages = [ "images/image0.jpg", "images/image1.jpg", "images/image2.jpg", ];
Hmmm. There's line breaks in there. Try it on one line.
Near as I can tell tell Safari handles arrays the same as othres. At least I
haven't seen problems.
Jeff then referenced like this:
document.images[1].src = myImages[1];
Is this a known bug with Safari? Broken arrays?
(BTW the above works in every major browser's recent version; those I have tried)
I can write a string literal into the src property:
document.images[1].src = "images/image1.jpg";
and achieve image replacement, but not when the string literal is referenced from an array.
What gives? Am I doing something Really Stupid (TM)?
Thanks in advance for advice.
Cheers, DK
[1] Referring to Safari version 1.0.1
This was a weird one...
Here's the bottom line:
Be careful to not use the same names in varible namespace and
selector namespace on Safari version <= 1.2.1 (125.1).
I was doing something like this:
document.getEle mentById("myIma ge").src = myImage[index];
where I had an array of strings labelled "myImage" and
and id selector in the HTML called "myImage".
When the JavaScript array name was modifed so that it would
not clash with the id selector, Safari worked properly.
So, my way of fixing it was simply to the change my array name
to "myImages" array.
Cheers,
DK
Duderonomoy <Se*@reply.to > wrote in message news:<pa******* *************** ******@reply.to >... where I had an array of strings labelled "myImage" and and id selector in the HTML called "myImage".
When the JavaScript array name was modifed so that it would not clash with the id selector, Safari worked properly.
Does it have the same behaviour as IE then. You can refer to a page
element in javascript by its id attribute value? For example if you
have
[xml id="xmlData"][/xml]
In javascript you can refer to it like this:
xmlData.src = '/xml/data.xml';
If so that'd be the cause of the clash.
On Sat, 24 Apr 2004 06:27:20 GMT, Duderonomoy <Se*@reply.to > wrote:
[snip] I was doing something like this:
document.getEle mentById("myIma ge").src = myImage[index];
where I had an array of strings labelled "myImage" and and id selector in the HTML called "myImage".
When the JavaScript array name was modifed so that it would not clash with the id selector, Safari worked properly.
So, my way of fixing it was simply to the change my array name to "myImages" array.
How did you declare the identifier? In IE, using the var keyword overrides
document globals for that scope (IDs and the like).
Mike
--
Michael Winter M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
On Sun, 25 Apr 2004 00:20:27 +0000, Michael Winter wrote: On Sat, 24 Apr 2004 06:27:20 GMT, Duderonomoy <Se*@reply.to > wrote:
[snip]
I was doing something like this:
document.getEle mentById("myIma ge").src = myImage[index];
where I had an array of strings labelled "myImage" and and id selector in the HTML called "myImage".
When the JavaScript array name was modifed so that it would not clash with the id selector, Safari worked properly.
So, my way of fixing it was simply to the change my array name to "myImages" array.
How did you declare the identifier? In IE, using the var keyword overrides document globals for that scope (IDs and the like).
Mike
Thanks for the reflective surface :)
Hmmm. I am not sure of the ramifications of what you are indicating.
Though I am very interested. I assumed such symbolic names would be
in different name spaces.
I was declaring data like this, in a separate file:
var demoText = [
"string one",
"string two",
"string thr",
]
var demoImage = [
"string/path/one.jpg",
"string/path/two.jpg",
"string/path/thr.jpg",
]
In another file an event handler:
function ClickHandler (evt)
{
<snip>
document.getEle mentById("demoI mage").src = demoImage[idx];
document.getEle mentById("demoT ext").innerHTM L = demoText[idx];
<snip>
}
And finally the HTML file:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=ut f-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<script src="data.js"></script>
<script src="events.js" ></script>
</head>
<body>
<img id="demoImage" src="">
<p id="demoText">b lah</p>
</body>
</html>
Cheers,
DK
Duderonomy wrote:
<snip> I was declaring data like this, in a separate file:
var demoText = [ "string one", "string two", "string thr",
^ ]
var demoImage = [ "string/path/one.jpg", "string/path/two.jpg", "string/path/thr.jpg",
^ ]
<snip>
A running theme in your Array literal definitions is a final Elison,
which is allowed but is known to be inconstantly handled across
browsers. ECMA 262 would require the resulting Array to be 4 elements
long with the first three elements containing strings and the fourth
element undefined. There doesn't seem to be any good reason for creating
Arrays that are longer than the number of string literals they contain
and any looping up to demoText.length , for example, may result in the
final undefined element being used (with potentially error-producing
results).
Richard.
"Richard Cornford" <Ri*****@litote s.demon.co.uk> writes:
[Array written ["a","b","c" ,]...] A running theme in your Array literal definitions is a final Elison, which is allowed but is known to be inconstantly handled across browsers. ECMA 262 would require the resulting Array to be 4 elements long with the first three elements containing strings and the fourth element undefined.
No, ECMA 262 v3 (haven't checked earlier versions) would required the
array to have length 3.
The relevant rule of 11.1.4 is
ArrayLiteral : [ ElementList , Elision_opt ]
where ElementList matches the three strings separated by commas,
and Elision_opt is empty.
If you check the evaluation of this rule
---
The production ArrayLiteral : [ ElementList , Elisionopt ] is
evaluated as follows:
1. Evaluate ElementList.
2. Evaluate Elision; if not present, use the numeric value zero.
3. Call the [[Get]] method of Result(1) with argument "length".
4. Call the [[Put]] method of Result(1) with arguments "length" and
(Result(2)+Resu lt(3)).
5. Return Result(1).
---
the ElementList evaluates to the array ["a","b","c"]. The rule for
ArrayLitreals increases the length of this array with the size of the
(empty) Elision (it specifically says to use zero if the elision is
omitted). It does not include the litreal comma of the rule in this
count.
I believe this rule is deliberate, attempting to mimic Java's
literal array notation, where a final comma is allowed.
However, IE 6 still fails to implement this correctly, and thinks
["a",].length == 2, so there is reason to omit the unnecessary comma.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen wrote: "Richard Cornford" <Ri*****@litote s.demon.co.uk> writes:
[Array written ["a","b","c" ,]...] A running theme in your Array literal definitions is a final Elison, which is allowed but is known to be inconstantly handled across browsers. ECMA 262 would require the resulting Array to be 4 elements long with the first three elements containing strings and the fourth element undefined. No, ECMA 262 v3 (haven't checked earlier versions) would required the array to have length 3.
The relevant rule of 11.1.4 is ArrayLiteral : [ ElementList , Elision_opt ] where ElementList matches the three strings separated by commas, and Elision_opt is empty.
If you check the evaluation of this rule --- The production ArrayLiteral : [ ElementList , Elisionopt ] is evaluated as follows: 1. Evaluate ElementList. 2. Evaluate Elision; if not present, use the numeric value zero. 3. Call the [[Get]] method of Result(1) with argument "length". 4. Call the [[Put]] method of Result(1) with arguments "length" and (Result(2)+Resu lt(3)). 5. Return Result(1). --- the ElementList evaluates to the array ["a","b","c"]. The rule for ArrayLitreals increases the length of this array with the size of the (empty) Elision (it specifically says to use zero if the elision is omitted). It does not include the litreal comma of the rule in this count.
It comes down to that separating comma in the ArrayLiteral production,
is it an Elison itself or just a separator of the ElementList from any
following optional Elison? Reviewing the production rules with the comma
in that rule highlighted I tend to agree with you that an isolated
trailing comma should not make the Array any longer than the
ElementList.
I seem to remember having this discussion with you before, your
conclusion didn't stick in my memory because I prefer to deal with the
issue by avoiding even attempting to defined sparse arrays, and never
include trailing commas.
I believe this rule is deliberate, attempting to mimic Java's literal array notation, where a final comma is allowed.
However, IE 6 still fails to implement this correctly, and thinks ["a",].length == 2, so there is reason to omit the unnecessary comma.
There is no question that this is an area of inconsistent
implementations that is best avoided entirly.
Richard.
On Sun, 25 Apr 2004 14:40:12 +0100, Richard Cornford wrote: Duderonomy wrote: <snip> I was declaring data like this, in a separate file:
var demoText = [ "string one", "string two", "string thr", ^ ]
A running theme in your Array literal definitions is a final Elison, which is allowed but is known to be inconstantly handled across browsers. ECMA 262 would require the resulting Array to be 4 elements long with the first three elements containing strings and the fourth element undefined. There doesn't seem to be any good reason for creating Arrays that are longer than the number of string literals they contain and any looping up to demoText.length , for example, may result in the final undefined element being used (with potentially error-producing results).
Richard.
Thanks for that feedback. It prompted me to make two version of my data
file, both with and without the trailing Elision. After testing it is
clear that such an issue was not causing the problem. Regardless, I will
not be inserting the Elision at the end of such definitions any more... I
never did that any other languages; so why start now. :)
Also, my code does not iterate across the array... Hence I would not
encounter this issue of a potentially undefined value.
Ultimately, the index, idx, is generated by an 'id' selector value of a
unique menu item; in my case, a Handler is tied to the onClick property of
a series of LI boxes that serve as menu items. So, when a menu item box is
clicked, an integer index value is derived from a unique id selector value
specified as an attribute of every LI element.
Thanks for the excellent feedback everyone... :)
I certainly know more stuff than before I asked you folks about this...
I submitted this issue as a bug against Safari. I'll follow-up here with
Apple's response.
Cheers,
DK This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bernard |
last post by:
Hi,
I am suddenly getting Safari script errors with the following user
agent:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/125.2 (KHTML,
like Gecko) Safari/125.8
In a frameset scenario, the framesetting document (top) contains a
|
by: joaopedrogoncalves |
last post by:
Hi,
I want to load an external javascript file, get its results and stick
them inside a <div> block. I also
want to do this in several places on a web page.
This way the browser doesn't have to wait for the external resource to
load to show up the page,
thus giving a perceiving faster load time for the user.
|
by: Giuseppe Chielli |
last post by:
Hi to everyone? Can someone tell me if there is a way to identify
Safari...I found out that navigator.appName returns "Netscape" and I
didn't found any option to change the browser's definition...
I can use document.all for IE, and so on but what can I do with Safari?
I need to distinguish Safari from other browsers...
Thanks to everyone.
|
by: Pasquale |
last post by:
With the code below, can anyone see why the array and/or the field in
the last line are empty for Safari users? It works with Netscape 6 and
up, IE 6, Firefox, Konqueror.
Thanks,
Pasquale
//begin
|
by: laredotornado |
last post by:
Hi,
Is it possible to fool Javascript running on a Mac Safari web
browser into believing it is a PC IE browser? We have the following JS
code that is detecting both Mac and Safari. Sadly, we do not have
control over the code.
// Global variables for platform branching
var NN, IE, MAC, browserVersion
| |
by: Joe Cox |
last post by:
I am having a problem with style properties for dynamic images in Mac OS X
Safari. By dymanic images, I mean images allocated with the javascript 'new
Image()' call.
With static images (created with the html <img> tag), I can make the image
visible or not, i.e. '<img style="visibility='hidden'" src='xxxx'/>'. But if
I create the image dynamically with javascript: new Image() then try to
modify the style, Safari chokes, and the Debug...
|
by: vendredi5h |
last post by:
Hello,
Yesterday I spent a lot of time to find why my javascript script was
not working on Safari. I finaly found a solution but not the reason.
And I'd like to know if someone could tell me if what seems to be an
esotheric bug is actualy not!
Here is the problematic part:
-------------------------------
|
by: Tom |
last post by:
I have an oo-type javascript program running perfectly on IE 6.0+, FF
1.5+, and Opera 7+ on Windows 98+, Linux (RH 9, FC 6), and Mac OS X.
4. As usual, the Safari browser is not working correctly, and because
it lacks an internal debugger, I'm completely unable to see what the
problem is.
So I downloaded that "Drosera" debugging program, but I'm finding it
useless for the following reasons:
1) I cannot "Attach" it to Safari 2.0...
|
by: GinnTech |
last post by:
I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the
latest Safari.
Here is the issue. I am attempting to call functions within a flash
object. When trying to attempt to retrieve the object to call the
functions IE6 IE7 FF2 FF3 all return Objects to work with. In Safari
a function is returned. Here is the code.
/
|
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...
|
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,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |