0

Not an expert, a total beginner trying to learn... I'm using a very basic html5 audio code, which I'm putting inside an iWeb 'widget'. It works fine in terms of playing the audio, and I understand about expanding the browser fall back and other options later. But - what I want it to do is make the window automatically go to a new web page when the track has finished. So there is some script afterwards taken from a website that claims to do this... This is the code I am using:

<audio controls autoplay>
<source src="AUDIO FILE LOCATION.mp3" type="audio/mp3">
<object data="mediaplayer.swf?audio=AUDIO FILE LOCATION.mp3">
<param name="movie" value="mediaplayer.swf?audio=AUDIO FILE LOCATION.mp3">
</object>
</audio>

<script>  
var audio = document.getElementsByTagName('audio')[0];   
audio.onended = function(e) {window.location='http://www.google.com';}  
</script>  

When I view this in the browser, the song ends and Firefox and Safari both show "connecting to google.com, spin for a couple of seconds and then nothing happens. Page stays where it is and audio player disappears. The onended event seems to be triggering google, but google is then not loading properly. I'm stuck. Can anyone help?

  • Do you mean to be setting `window.location.href = "..."`? – Casey Falk Aug 04 '14 at 14:59
  • Also, see this post: http://stackoverflow.com/questions/7077770/window-location-href-and-window-open-methods-in-javascript – Casey Falk Aug 04 '14 at 14:59
  • many thanks for your answer. Adding the .href as above makes no difference - same symptoms as in my post. But I read your other link and tried window.open('http://www.google.com'); and that definitely works (opens google in a new tab in firefox). Trouble is I need it to open in same window, same tab etc. It is going to direct to another audio page.... this is bizarre. – user3907063 Aug 04 '14 at 15:38
  • Try `window.location.replace("...")` instead? (source: http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript/506004#506004) – Casey Falk Aug 04 '14 at 15:42
  • From the post you posted "window.location.href will open the URL in the window in which the code is called. " Could it be that the browser is trying to open google within the actual parameters of the audio player and not the containing web page? – user3907063 Aug 04 '14 at 15:43
  • Ahhh, interesting. If the iWeb widget gets its own frame then that is possible! – Casey Falk Aug 04 '14 at 15:44
  • 1
    I am answering my own question... i think this is an issue with iWeb – user3907063 Aug 04 '14 at 15:45
  • Have just pasted code into html body of the webpage instead of via iWeb. It works. Thanks a lot helping to tune my brain towards a different direction. – user3907063 Aug 04 '14 at 16:04
  • No prob. Since you solved it, feel free to answer your own question or make it a community answer. : ) – Casey Falk Aug 04 '14 at 16:05

0 Answers0