This code was written by acoder serveral (139) days ago. So I decided to post it. -
-
function play() {
-
embed = document.createElement("embed");
-
embed.setAttribute("src", "soundfile.wav");
-
embed.setAttribute("hidden", true);
-
embed.setAttribute("autostart", true);
-
document.body.appendChild(embed);
-
}
-
-
^_^ Thanks, Death
3 18565 gits 5,390
Expert Mod 4TB
to make it a little bit more useful we should slightly adapt it to accept the file to play as a parameter, and strictly seen we should declare the variable embed :) -
-
function play(file) {
-
var embed = document.createElement("embed");
-
-
embed.setAttribute('src', file);
-
embed.setAttribute('hidden', true);
-
embed.setAttribute('autostart', true);
-
-
document.body.appendChild(embed);
-
}
-
so now we could simply call: - onclick="play('file.wav');"
on any element we want ...
kind regards
I probably posted that from somewhere - no need to attribute it to me.
Besides the points made above, embed is actually non-standard, but sometimes required for backwards compatibility. The element to use now is object.
gits 5,390
Expert Mod 4TB
I probably posted that from somewhere - no need to attribute it to me.
Besides the points made above, embed is actually non-standard, but sometimes required for backwards compatibility. The element to use now is object.
so we could adapt it further :) -
-
function play(file, obj) {
-
if (typeof obj == 'undefined') {
-
obj = 'object';
-
}
-
-
var node = document.createElement(obj);
-
-
node.setAttribute('src', file);
-
node.setAttribute('hidden', true);
-
node.setAttribute('autostart', true);
-
-
document.body.appendChild(node);
-
}
-
now we could call: - onclick="play('file.wav');"
that creates the 'object' as default or: - onclick="play('file.wav', 'object');"
or even with 'embed' instead of 'object' in case we need to do that ;)
kind regards
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Paul Moore |
last post by:
Does anyone know of a Python library which handles sound file formats
(MP3, Ogg, FLAC are the three I'm nost interested in). I'd like
something that can manipulate "metadata" - stuff like artist,...
|
by: Kim Forbes |
last post by:
Hello all,
I have simple function that I call from an alert box
alert(testScore);
It works fine. Unfortunately, I do not like the sound and Exclamation
point icon that appears. I'd like a...
|
by: Peter Schmitz |
last post by:
Hi,
I'm just trying to play a *.wav file, making use of the unmanaged function
"sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid,
that the sound file itself has to be...
|
by: Serdge Kooleman |
last post by:
hi
i'm trying to play sounds in my windows app.
wav files are in the same folder as .exe
if i'm getting path by command:
ApplicationPath = Application.StartupPath;
and it is look like
|
by: Lam |
last post by:
how can I play sound file in a .aspx page written in C#?
I try to use the code like the following. But whenI call the play function
play("sound.wav", this.SND_ASYNC)
my computer give out "be"...
|
by: Xero |
last post by:
Is there a simpler way to play from a sound file than this one
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcode/html/vbtskcodeexampleplayingsound.asp
Thanks.
--
Xero
...
|
by: Benzerari |
last post by:
Hi All;
Please, if any one knows the visual basic code, to be added to a Stop button in order to stop playing some sound of (*.Wav) type. I have achieved to find the code for start playing sound...
|
by: Jake Barnes |
last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching
for "how to play a sound with Javascript". I'm somewhat suprised that
the majority of entries are from the 1990s, and there are...
|
by: Sheena777 |
last post by:
I want to Play a specific sound file in my code when a certain event happens, but i don't know how. I can play the system sounds in my program and I know how to start the media player to play an mp3...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
| |