473,405 Members | 2,373 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,405 software developers and data experts.

cross platform problem with javascript on mac os x

Hi all
I'm new to JavaScript and working my way through the Teach yourself JS 1.5 book. All of the scripts in the book work perfectly apart from the listing 20.3 piano example. http://www.jsworkshop.com/js15/list20-3.html

I am using an iMac G5 Mac OSX 10.4.10 Tiger and am getting the error

Expand|Select|Wrap|Line Numbers
  1. document.embeds[note].play(); is not a function
This is the actual code

Expand|Select|Wrap|Line Numbers
  1. <title>JavaScript Piano</title>
  2. <script LANGUAGE="JavaScript" type="text/javascript">
  3. function playnote(note) {
  4.   document.embeds[note].play();
  5. }
  6. </script>
  7. </head>
  8. <body>
  9. <embed SRC="C0.wav" HIDDEN=true AUTOSTART=false>
  10. <embed SRC="Cs0.wav" HIDDEN=true AUTOSTART=false>
  11. <embed SRC="D0.wav" HIDDEN=true AUTOSTART=false>
  12. <embed SRC="Ds0.wav" HIDDEN=true AUTOSTART=false>
  13. <embed SRC="E0.wav" HIDDEN=true AUTOSTART=false>
  14. <embed SRC="F0.wav" HIDDEN=true AUTOSTART=false>
  15. <embed SRC="Fs0.wav" HIDDEN=true AUTOSTART=false>
  16. <embed SRC="G0.wav" HIDDEN=true AUTOSTART=false>
  17. <embed SRC="Gs0.wav" HIDDEN=true AUTOSTART=false>
  18.  
  19. <embed SRC="A0.wav" HIDDEN=true AUTOSTART=false>
  20. <embed SRC="As0.wav" HIDDEN=true AUTOSTART=false>
  21. <embed SRC="B0.wav" HIDDEN=true AUTOSTART=false>
  22. <embed SRC="C1.wav" HIDDEN=true AUTOSTART=false>
  23. <h1>The JavaScript Piano</h1>
  24. <hr>
  25. <p>Click on the funny-looking piano keys below to play a melody.</p>
  26. <hr>
  27. <a HREF="#" onClick="playnote(0)">
  28.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  29. <a HREF="#" onClick="playnote(1)">
  30.    <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
  31. <a HREF="#" onClick="playnote(2)">
  32.  
  33.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  34. <a HREF="#" onClick="playnote(3)">
  35.    <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
  36. <a HREF="#" onClick="playnote(4)">
  37.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  38. <a HREF="#" onClick="playnote(5)">
  39.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  40. <a HREF="#" onClick="playnote(6)">
  41.    <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
  42. <a HREF="#" onClick="playnote(7)">
  43.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  44.  
  45. <a HREF="#" onClick="playnote(8)">
  46.    <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
  47. <a HREF="#" onClick="playnote(9)">
  48.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  49. <a HREF="#" onClick="playnote(10)">
  50.    <img border=0 SRC="blackkey.gif" ALIGN=TOP></a>
  51. <a HREF="#" onClick="playnote(11)">
  52.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  53. <a HREF="#" onClick="playnote(12)">
  54.    <img border=0 SRC="whitekey.gif" ALIGN=TOP></a>
  55. <hr>
  56. </body>
  57. </html>
  58.  
I can get the notes to play by putting the wav file path in the href but this then shows the QT plugin for each note which seems to overide the embed tag

The example works fine In IE on virtual pc but does not play on Firefox Netscape or Safari on the Mac even from the sites workshop example.
I have heard that different platforms handle script in different ways and i am sure there is a simple solution, but being new to JavaScript i am unable to troubleshoot this any further.
I have asked on other forums and been told its possible mac does not support
this function but given no way to resolve the issue.
I apologize if this is an faq but any help would be much appreciated to get this to work on the mac.
Thanks in advance
Aug 21 '07 #1
3 1944
pbmods
5,821 Expert 4TB
Heya, Sonsofsound.

Instead of document.embeds, try:
Expand|Select|Wrap|Line Numbers
  1. document.getElementsByTagName('embed')[note].play();
  2.  
Aug 21 '07 #2
Heya, Sonsofsound.

Instead of document.embeds, try:
Expand|Select|Wrap|Line Numbers
  1. document.getElementsByTagName('embed')[note].play();
  2.  
Hi pbmods
Thanks for the suggestion and quick reply.
I tried this and it improved the situation slightly now the sounds are playing, but
the QT plugin is still showing after each onClick and the error is the same.
error:
Expand|Select|Wrap|Line Numbers
  1. document.getElementsByTagName('embed')[note].play(); is not a function
been doing some more research but still no solution why the hidden attribute/value is not working In the embed tag also tried bolean yes and 1.
I have used this in html in other pages without javascript and it works fine. also tried putting the script inline as well.
Any ideas.
Thanks again
Aug 31 '07 #3
pbmods
5,821 Expert 4TB
Heya, Sonsofsound.

Try giving each embed an ID and then using document.getElementById().
Aug 31 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Karsten | last post by:
Hi I'm a really a new with this cross platform development, so I have some dumb questions, which I hope you can help me with. If there is a better newsgroup for this question, please point...
7
by: Web Master | last post by:
Are there any good websites or books that deal with cross platform XML? I'd like to target Internet Explorer/Netscape Navigator 5 or later, as well as Opera, possibly konqueror on Linux as well. ...
0
by: demibee | last post by:
Thought this might be of interest to some out there... For those who've never encountered it, it's a free, open-source, cross-platform GUI library (Windows/Mac/Linux). Forte's Agent 2.0 will be...
14
by: John Salerno | last post by:
Bear with me, but I've been reading a lot about how the .NET languages are platform independent, and I assume this means a program written in C# can be run on a Unix or Mac machine. If this...
9
by: permanent.tourist | last post by:
I'm having a hell of a job getting this to work in Safari: the only thing I can think of is that one can't use reload() across to another frame for security reasons. Does anyone have a concrete...
7
by: Charles | last post by:
I'd like to develop a simple cross-platform application in C++. I'd like it to run in Windows, OS X, PC-BSD and Linux. From my research, it seems I should use Qt or Gtk as a graphical library. Do...
5
by: Michael Reichenbach | last post by:
After working with script languages, notepad(++) and co. and several other ide`s I found something which really improved my productivity (Visual Studio 2005). It`s imho better then dev-cpp... I...
12
by: Tomás Ó hÉilidhe | last post by:
I don't know the first thing about cross-platform GUI programming, so I'd like to ask a few quick questions. Which library is best for someone who appreciates portable programming and correct...
1
by: Vinod Sadanandan | last post by:
Cross Platform Migration An Unproblematic Approach (Windows-UNIX ) Oracle 10\11g The principal restriction on cross-platform transportable database is that the source and destination platform...
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...
0
marktang
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,...
0
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...
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
isladogs
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...

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.