Opera Javascript bug? (works in Firefox)

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2007
Posts: 2
Reputation: bball7210 is an unknown quantity at this point 
Solved Threads: 0
bball7210 bball7210 is offline Offline
Newbie Poster

Opera Javascript bug? (works in Firefox)

 
0
  #1
Jun 28th, 2007
All,

I am currently developing a UserJS "plug-in" for Opera in Linux using verision 9.21, build 641. I have encountered some bizarre problems and have been able to isolate and reproduce one using the code posted below. The basic issue throughout my code (and reproduced below) is that a command may either not execute, may execute incorrectly, or may execute differently depending on whether or not an alert() precedes it. Using Firefox, preceding the alert(hidden.contentDocument) command with another alert does not change anything (as well it shouldn't).

Has anyone else encountered this or have any suggestions? I cannot afford to have random alerts throughout my code (obviously).

Thanks in advance!
Louis

  1.  
  2. <html>
  3. <body>
  4.  
  5. <script type="text/javascript">
  6.  
  7.  
  8. var hidden = document.createElement('iframe');
  9. hidden.src = "http://www.opera.com";
  10. hidden.id = "iframe"
  11. document.body.appendChild(hidden);
  12. // if the below alert is commented out, the alert(hidden.contentDocument) command displays an alert box saying "null".
  13. // if the below alert is not commented out, the alert(hidden.contentDocument) command displays an alert box saying "[object HTMLDocument]".
  14. //alert("stuff")
  15. alert(hidden.contentDocument)
  16.  
  17. </script>
  18.  
  19.  
  20. </body>
  21. </html>
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Opera Javascript bug? (works in Firefox)

 
0
  #2
Jun 28th, 2007
Where is the semicolon that belongs after each alert statement? You have a run-on statement.

The next statement is not executed because the semicolon is missing. The interpreter thinks the statement is not over yet. It then finds it doesn't know what to do with the improper code it finds, and skips to the next semicolon.

Some interpreters incorrectly ignore missing semicolons when it is "obvious" that a new statement has been started. They should not do that. And you should never count on it happening.
Last edited by MidiMagic; Jun 28th, 2007 at 7:12 pm. Reason: sin tax
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: bball7210 is an unknown quantity at this point 
Solved Threads: 0
bball7210 bball7210 is offline Offline
Newbie Poster

Re: Opera Javascript bug? (works in Firefox)

 
0
  #3
Jun 28th, 2007
Midimagic,

Thanks a lot for the clarification. I am new to Javascript and was under the impression that semicolons were optional. Some are there because of my C++ habits.

Thanks again,
Louis
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Opera Javascript bug? (works in Firefox)

 
0
  #4
Jun 28th, 2007
Javascript standards don't mandate semicolons but always make sure you put them because there are many browsers out there who would like to suck your project in.
Last edited by ~s.o.s~; Jun 28th, 2007 at 10:41 pm.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,203
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Opera Javascript bug? (works in Firefox)

 
0
  #5
Jun 29th, 2007
That's a difference between Java and JavaScript.

Actually, there are certain places in JavaScript where semicolons are required (between statements), some places where they are optional (before a close brace), and some places where they are prohibited (before an else).
Last edited by MidiMagic; Jun 29th, 2007 at 1:37 am.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,609
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Opera Javascript bug? (works in Firefox)

 
0
  #6
Jun 29th, 2007
> Actually, there are certain places in JavaScript where semicolons are required
Here you are talking about the syntax (for example the for loop) which mandates semicolon be placed. In Javascript as long as statements are separated by whitespaces (newlines) it shouldn't be a problem, though older / non-complaint browsers balk at it.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC