This has been asked already, but the solution there did not help me. What does this mean exactly? My regular HTML page uses a "script" tag to load my main_script.js file, where the first thing I do is:
var internetExplorerSucks = 30;
The variable used be be called FPS, but I thought it might have been taken by some random default global, so I renamed it to something that obviously isn't already taken. Still it fails to work. I get this error in the IE debug console:
SCRIPT5039: Redeclaration of const property
main_script.js, line 1 character 1
I tried making it a global by taking out "var", still didn't work. It should be noted that this is not in any function, just literally the first line of code in the file.
Some background: All of this code works perfectly in Chrome, Firefox, and Safari on Windows, OS X and Linux. IE is the only browser this does not work on. This project involves using an HTML5 canvas, which I got to at least display in IE 9 (I am using version 9), but this code does not immediately pertain to the canvas at all. In fact, I cannot seem to declare any variables whatsoever in my main_script.js file. I am able to, however, create functions without running into an error. Is that what I have to do? Put everything in a function (that would involve a lot of moving things around)?
Anyway, thanks for the help.
P.S. Internet Explorer is a nightmare.
I had the same problem in my code and it turn out that IE show wrong line were the redeclaration appear. In my case it was history I use later in the code. You should check whole code for redeclaration of the constants. You can try to comment out part of the code and see when it throw that error.
Related
H ey there,
I am developing small web-application based on a lot of PHP and JS code and by chance opened the current index.php in Firefox instead of Chrome (my main dev browser).
I was rather shocked to see that one of my main components, a chart (made with amCharts), was not rendered at all. Strangely enough, the watermark of amCharts is shown...
Now I thought it just a hickup and opened the IE to have another browser for comparison, however, same problem there.
I went back to Chrome and everything is still fine there. This really confused me and made me think that it's a code problem, e.g. an unclosed parenthesis somewhere. So I copy pasted my code into several PHP / JS / HTML validators and none had any hits.
In addition I downloaded the Firebug addon for Firefox hoping to find some kind of error, but there is none to be found.
What I also tried to inserting some "console.log" passages in my code to see whether the code execution stops at some point, no luck either. All log messages are shown with their correct values.
Right now I am kinda at my wits end...
Does anyone have an idea / had a similar problem and knows how to solve this or what causes this or how I could find out what causes this?
Any help you can provide would be greatly appreciated.
best regards,
daZza
EDIT:
I fine-tuned the console.log commands and basically backtraced every single step. I now have found the problem, but don't know the source of it. Basically my whole view of logic in programming is breaking apart now... One and the same command returns a different result in another browser, what the hell?!
Here's are some code snippets from the problem area:
xmlData = xmlHttp.responseXML;
var x=xmlData.getElementsByTagName("row");
xmlRowCount = x.length;
console.log("Rowcount: " + xmlRowCount);
for (i=0;i<xmlRowCount;i++)
{
do something with every row in the source xml file
}
Now the problem is that in Chrome the rowcount is correctly returned as 417. FF returns 0 (I guess IE as well).
How can that be possible? How can a predefined command return different values? I just don't get it...
Edit2: To make the browser test complete, I also downloaded and tested Opera. It works fine there, which makes this whole thing even stranger. What is the difference between IE/FF vs. Chrome/Opera?
PS: Here's two screenshots (Chrome and FF) to visualize the problem:
Can you try to use the below code
var x=xmlData.body.all.tags("row");
or
var x=xmlData.all.tags("row");
Hope it helps.
I developed a .htm document with an in-built script for javascript to run a program. In google chrome, the program works fine, but I got a beta test complaint that it didn't work on firefox 14.01 or opera. On testing with firefox 14.01, I can confirm it doesn't work (I assumed opera to be the same). I cannot insist the audience upgrade their browsers, as this is supposed to be widely compatible.
Doing a little tracing of the issue, I installed Firebug, which, on clicking the Javascript button to generate a coordinate the first time, it worked (clearly showing the function is defined and exists), but the second time, Firebug complained that:
"ReferenceError: GenerateCoord is not defined".
This wouldn't be so ironic if it only did this after generating an (encrypted) coordinate (thus calling GenerateCoord that is supposedly 'undefined').
If one looks in the code, one can clearly see that the function GenerateCoord is clearly defined before it is called. I would say firefox has an 'onclick' issue, but then it begs the question why did it work the first time I clicked it (calling GenerateCoord via 'onclick') but not the second?
Reloading the file allows the button to work the first time, and the first time only. I am baffled as to how firefox can call a function one time that it then says is undefined the next. Am I missing something here?
Javascript and HTML code can be viewed here:
http://pastebin.com/4qykTfEW
-
How do I solve the problem, and is there an easier solution than re-writing the code to avoid onclick (that seems to work in certain circumstances but not others)?
The problem is that using document.write overwrites the entire HTML page, thus inadvertently removing the GenerateCoord script. I'd suggest appending the link to the document (in ShowTarget) rather than attempting to re-write it.
For example, have a container element where the link should be:
<div id="links_container"></div>
Then to append the links, use:
document.getElementById('links_container').innerHTML = Link;
I have a simple script that should cause one of three divs to be visible while the other two are not. The function that does the work is called like so:
onchange="switch(this);"
Firebug indicates that there is an error with this text:
Javascript Error: missing { before switch body
The erroneous code it indicates is line one of my .php file where the doctype is defined like so:
<!doctype html>
The funny thing here is that I have another page with the same doctype and a script that is virtually identical which works 100%. The only differences between the two pages are that in the one that does work, I call the script from
One more thing about the Firebug output: On the page that works, the firebug script window shows the javascript like so:
function onclick(event) {
switch(this);
}
Now, on the page where the script doesn't work, Firebug shows no output that has anything to do with onchange, onclick, or anything else. It just shows the code from my javascript file and tells me I am missing the opening bracket to the function when it is clear as day that it's there. Perhaps, even with the script in the head of my main php file, something odd is happening with scope, making the defined function invisible to the callers. Any ideas?
1: why would Firebug tell me the error is on line 1 where the doctype is defined when the function that fails isn't even in the same file?
2: Does the doctype effect the way that javascript runs, and how do I debug it if it does?
I would prefer to continue using only HTML5 for this project and use a javascript file for backwards compatibility. Any help is very welcome!
P.S. I am running Ubuntu 11.10 with Apache2, PostgreSQL, and PHP5. Everything works perfectly outside of this one javascript issue.
EDIT: Totally stupid question, but I guess these things happen sometimes. As stated in the answers, switch is a keyword in Javascript and changing the name of my function fixed the problem. I really should have noticed that since my editor highlights keywords in brown...
I am not deleting this post (unless someone else suggests I do) in case someone else out there runs into the same problem. I am giving the answer to the guy who answered it first because his answer also explained the reason why I was getting the error messages I was getting, which is probably more helpful in the long run than a simple awareness of switch statements.
This error has nothing to do with your doctype or HTML5. It occurs because switch is a reserved word used for switch statements; you cannot name a function switch.
So when you do switch(this) the JavaScript engine is expecting you to follow that up with the rest of the switch statement, including the opening {, the switch body, and then the closing }. When you don't do that, it throws the given error.
The error is on "line 1" because you used an inline event handler, which in Firebug's mind is a JavaScript file with one line---that line simply being switch(this);. Firebug does not deal in line numbers of HTML files, only those of JavaScript files---whether they be real JavaScript files, or "virtual" ones generated by inline event handlers.
switch is a keyword in javascript, rename your function to something else like myswitch.
switch is a keyword in Javascript
We have this fun example of how our EcmaScript/JavaScript Obfuscator works.
We provide links that show the unobfuscated and obfuscated Ecmascript source for a
"dynamic clock". When you press the start button you will see that the clock graphic parts follow your mouse movements and when you stop moving the mouse it forms a ticking circular clock.
See here ...
http://www.semdesigns.com/Products/Obfuscators/ECMAScriptObfuscationExample.html
The issue that both the un-obfuscated and obfuscated code works fine with Internet Explorer but not with FireFox. So what is the difference between EcmaScript for FireFox and Internet Explorer that results in this code working with Internet Explorer but not with FireFox is the question? I have tried this several versions of FireFox including the latest version and all fail.
First place to check is the "Error Console" or your Firebug console - finding it depends on your version of Firefox and whether or not you have Firebug installed.
I immediately found this in the console when trying out your page:
Error: document.getElementById("mzSeconds" + i) is null
Source File: http://www.semdesigns.com/Products/Obfuscators/UnobfuscatedJavaScriptMouseClock.js.txt
Line: 19
Update
Having found the error, and with Dexter and jfriend00 having pointed out why you're getting the error in the first place, we can see that the difference between IE and "all other" browsers in this case is not how they execute EcmaScript, but in how they construct the DOM in the face of HTML errors -- missing closing quotes on attributes in your case. (Though there are script differences those are not relevant here)
Your document.write() would output <div id="mzSeconds0 style="position:..."> which is invalid, leading to another debugging tool: validation.
If CSS rules or Javascript code behave strangely or inconsistently across browsers it's a good idea to validate your HTML (at validator.w3.org) because invalid HTML will be parsed in different ways by different browsers.
Your immediate problem is that you are generating invalid HTML code, appending it to the DOM, and then trying to find it again using document.getElementById.
The offending section is line 100 of UnobfuscatedHTMLPage.html, which contains this line:
document.write('<div id="'+(('mzSeconds'))+i+' style="position:absolute;top:0px;left:0px" width="15" height="15"><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></div>');
You're missing the closing " immediately after id="'+(('mzSeconds'))+i+', which causes the id of the div tag to be processed incorrectly in IE (two wrongs making a right, in this case).
There are a number of similar errors in that section of code - you'll need to fix them all (by debugging your code in Firebug or Chrome Developer tools) before your code will be valid and work in non-IE browsers.
A very simple look in the debug console of any browser that it doesn't work in would show you where the error was (I used Chrome). Then, a look at the DOM would show you why that error occurred. Use your debugging tools to find your problems.
I think the root issue is that when you generate your HTML, you are missing some closing quotes. That creates illegal HTML which different browsers barf on differently.
The first error in your code is triggered because no object with id="mzSeconds0" exists. This is caused because you are missing a closing double quote in this line:
document.write('<div id="'+(('mzSeconds'))+i+' style="position:absolute;top:0px;left:0px" width="15" height="15"><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></div>');
It should be this with the closing double quote at the end of id="mzSeconds0":
document.write('<div id="'+(('mzSeconds'))+i+'" style="position:absolute;top:0px;left:0px" width="15" height="15"><font face=Arial size=3 color='+sCol+'><center><b>'+S[i]+'</b></center></font></div>');
I think the same error exists on most of these types of lines and you will need to fix them all.
Checking a debugger yields: document.getElementById("mzSeconds" + i) is null and also includes line numbers and stack trace which should make fixing your bug easy.
The cause is that you are throwing invalid HTML to the browser which need to try to correct it somehow. Obviously you end up having a different DOM in IE an Firefox.
document.write('<div id="'+(('mzMinutes'))+i+' style="position:absol…
I still don't see the use of obfuscating JavaScript or writing code in your style. Write HTML directly instead of misusing JavaScript to do so. When you need to create content from JavaScript, then use DOM functions instead of document.write. This would have saved you from this bug.
When you are running your code to a debugger (Firebug), you'll find other bug popping up. Please do also have a look at JavaScript strict mode because it would probably save you a lot of time by pointing out bad practices.
I just discovered on my site using magento 1.3.2.2 that on a bundled product, when adding different options the price does not change in internet explorer. It works fine in all other browsers however.
In internet explorer I get the error message.
Message: Object doesn't support this property or method
Line: 34
Char: 9
Code: 0
URI: /skin/frontend/my_new_interface/design2/js/bundle.js
So I checked out line 34 and found
parts = selection.id.split('-');
I verified that selection.id is a string. I'm not a javascript expert and I'm not familiar with prototype.
On a lark I decided to split up the line as:
var parts = selection.id;
parts = part.split('-');
Well that fixed the problem. Furthermore I went back and just reduced to:
var parts = selection.id.split('-');
Which still worked as well. I don't think this is a file I should be messing with though. I'm assuming this javascript class should work fine in ie without me having to change anything.
I'm hoping someone has an idea of why this might have fixed the problem or what I can do to find out what the real problem is. Do you see any problem with me leaving this fix the way it is?
It's very possible that you hit an ID in the other case that didn't exist, and therefore it was attempting to split an undefined variable. If the fix works for you, stick with it, but you may want to consider upgrading your Magento installation. The series is onto 1.4 now, and there are huge numbers of fixes in every release.
Hope that helps!
Thanks,
Joe