Note that there are some explanatory texts on larger screens.

plurals
  1. POPage moves when I click in image
    primarykey
    data
    text
    <p>I have a page with an image that would play a sound in clicking on it. But when i click my page goes down if I'm at the top and up if I'm at the bottom of the page, for whatever reason. </p> <p>I tried all the solutions sugested here:<a href="https://stackoverflow.com/questions/8556203/onclick-javascript-playsound">How do I fire a javascript playsound event onclick without sending the user to the top of the page?</a></p> <p>but none seems to work. I've tried placing the javascript in the head or in the body tag, but the problem seems to persist whatever I do. I just need an image to play a sound when clicked, and not move (I will have hundreds of small images on the page and it will be a lot to scroll up or down if they keep moving my page).</p> <p>What am I doing wrong?</p> <p>Here is my code:</p> <p>` </p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ro" lang="ro"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Easy and Simple Learning &lt;/title&gt; &lt;script language="javascript" type="text/javascript"&gt; function playSound(soundfile) {document.getElementById("dummy").innerHTML="&lt;embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" /&gt;";} &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;span id="dummy"&gt;&lt;/span&gt; &lt;a href="#" onclick="playSound('sound.mp3');"&gt;&lt;img src="image.png" /&gt; &lt;/a&gt; &lt;/body&gt; &lt;/html&gt;` </code></pre> <p>PS: I am using Chrome, could that be an issue? Many thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload