Jump to content

javascript bypassed for href link


rubing

Recommended Posts

I had some code working fine, that was being generated dynamically by php.  Now, I entered it manually and can't get it to work at all either by pseudo or onclick method. 

 

 

<a href="javascript_required.html" onclick="soundManager.play('mySound','Rick.mp3')"><img src='images/bigplay.png' /></a>

Link to comment
Share on other sites

I had some code working fine, that was being generated dynamically by php.  Now, I entered it manually and can't get it to work at all either by pseudo or onclick method. 

 

 

<a href="javascript_required.html" onclick="soundManager.play('mySound','Rick.mp3')"><img src='images/bigplay.png' /></a>

 

In what way is it not working?

Link to comment
Share on other sites

Either get rid of the A tag and just use onclick of the image:

<img src="images/bigplay.png" onclick="soundManager.play('mySound','Rick.mp3');" />

or return false in the A tag:

<a href="javascript_required.html" onclick="soundManager.play('mySound','Rick.mp3');return false;"><img src='images/bigplay.png' /></a>

Link to comment
Share on other sites

General note, when using events, you need to return false in order to prevent the 'natural event'. So, your code before was running play, but then executing the natural event of going to javascript_required.html

Link to comment
Share on other sites

Yeah, after you said it I remebered reading that somewhere  ;D

 

I want to write some code to switch out the play button for a pause button while the music is playing.  Can I do that in the anchor's onclick code.  Or should i place that in the head??

 

 

 

Link to comment
Share on other sites

In your sound manager, have a play functoin and a pause function. Also, add a property to track the current status (playing or paused). Then, in your onclick, use a more generic function (like togglePlay). In togglePlay, determine which function to run by testing the status property, and then run that function.

Link to comment
Share on other sites

sounds like you've had experience with this script!  i appreciate the advise!  There's something about the javascript syntax that really bugs me, like for instance:

 

 

why does the sound manager put brackets inside parenthesis...e.g.:

soundManager.createSound({

id:'mySound1',

url:'../mpc/audio/CHINA_1.mp3'

});

 

Link to comment
Share on other sites

it's the same thing as sending a string as an argument, but instead, it's a javascript object (JSON). if it helps, think of it as this:

var myobj = {
id:'mySound1',
url:'../mpc/audio/CHINA_1.mp3'
};
soundManager.createSound(myobj);

If you aren't familiar with JSON, it's similar to an associative array in PHP.

Link to comment
Share on other sites

it's the same thing as sending a string as an argument, but instead, it's a javascript object (JSON). if it helps, think of it as this:

var myobj = {
id:'mySound1',
url:'../mpc/audio/CHINA_1.mp3'
};
soundManager.createSound(myobj);

If you aren't familiar with JSON, it's similar to an associative array in PHP.

 

Not to derail the thread, but technically that's not JSON.  That's object literal notation.  JSON is a subset of object literal notation that requires identifyers to be strings themselves (http://www.json.org/js.html).  So:

var myJSON = 
   {
      "id" : "mySound1",
      "url" : "../mpc/audio/CHINA_1.mp3"
   };

 

Is JSON.

 

Small nit to pick, I know, but the two aren't entirely the same.  To me, it's like saying ++i and i++ are the same thing.  Close, but not quite.  It also doesn't help when people like Dustin Diaz continue to call object literal notation JSON.

 

Anyway, it's just a pet peeve of mine.  My communication degree has turned me into something of a language/terminology fiend. :)

Link to comment
Share on other sites

can't argue with ya there, i'll do my best to pick my words better next time. the last thing i would want to do is stress a fellow coder out ;)

 

Mwahaha...my plan of foisting my hangups onto others one post at a time is coming to fruition! ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.