Note that there are some explanatory texts on larger screens.

plurals
  1. POPlaying audio via an iframe using javascript
    primarykey
    data
    text
    <p>I have the following code in <code>abc.jsp</code></p> <pre><code> &lt;% out.write("&lt;script type=\"text/javascript\" src=\"scripts/test.js\"&gt;&lt;/script&gt;"); out.write("Here is filename"+sfl); out.write("" + "&lt;input type=\"button\" id=\"playBt\" value=\"Play Now\" onClick=\"playSound()\" &gt;" + "&lt;audio id=\"sound\" preload=\"auto\"&gt;" + "&lt;source src=\"music.ogg\" type=\"audio/ogg\" /&gt;" + "&lt;source src=\"music.mp3\" type=\"audio/mpeg\" /&gt;" + "Your browser does not support the audio element." + "&lt;/audio&gt;" ); out.write(""); %&gt; </code></pre> <p>Then content above was brought in in a frame in <code>index.jsp</code></p> <pre><code> &lt;iframe id='bgframe' style='display:compact;' src='abc.jsp' width="400" height="200"&gt;&lt;/iframe&gt; </code></pre> <p>This JavaScript function is now used - <code>test.js</code></p> <pre><code>function playSound() { var frameRef = document.getElementById('bgframe'); var sound = frameRef.contentWindow.document.getElementById'sound'); //var sound = frameRef.contentDocument.document.getElementById('sound'); sound.play(); } </code></pre> <p>The problem is that, the sound does not play when I click on play button. On the JavaScript console, the system returns null as value of <code>frameRef</code>. Also, I get the following error depending on whether I use <code>contentDocument</code> or <code>contentWindow</code>.</p> <blockquote> <p><code>Uncaught TypeError: Cannot read property 'contentDocument'</code><br> <code>Uncaught TypeError: Cannot read property 'contentWindow'</code></p> </blockquote> <p>I've implemented different solutions but the uncaught typedef error remains. </p> <p>Please what am I doing wrong here and how can I fix it? Why can't I access elements on frame <code>id=bgframe</code>?</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