/    Sign up×
Community /Pin to ProfileBookmark

Two commands under one href?

How can I have two commands under one <a href>? It’s a MP3 file link; the first one starts playing the song, but on that click I want the page they are on to link to another page too. Thanks.

to post a comment
HTML

14 Comments(s)

Copy linkTweet thisAlerts:
@NeoboffinOct 08.2006 — You can do this by Javascript.

[code=html]<script language="javascript" type="text/javascript">
function letsGo(play, to)
{
// Your MP3 plyer stuff here.

// Go to link
window.location = to;
}
</script>[/code]


Then for your links add like:

[code=html]<a href="javascript: letsGo('mp3_file_to_play.mp3', 'new_url.html');">Play this MP3!</a>[/code]
Copy linkTweet thisAlerts:
@ZnupiOct 08.2006 — Or you could, more easily in my opinion, do something like :
[code=php]
<a href="javascript: function1(param); function2(); function3(); etc();">Link</a>
[/code]

Or ... if you want it to look pretty, and not print in the user's status bar all the functions that you call, use :
[code=php]
<a href="javascript:void(0)" onClick="function1(params); function2(); etc();">Link</a>
[/code]

I hope this helps...
Copy linkTweet thisAlerts:
@jamesx521authorOct 09.2006 — How should I include [B]target="_blank"[/B] for their MP3 player that will open, yet [B]target="_self"[/B] for the new page; does the code go outside the two (params), or inside?
Copy linkTweet thisAlerts:
@jamesx521authorOct 09.2006 — Where it says [I]Your MP3 plyer stuff here[/I] do I put MP3 file-names? Like this: [B]// test.mp3[/B]

Where it says [I]Go to link window.location = to;[/I] do I put the URL on the place of [B]to[/B]?

// Go to link

window.location = [B]test.html[/B];
[CODE]<script language="javascript" type="text/javascript">
function letsGo(play, to)
{
// Your MP3 plyer stuff here.

// Go to link
window.location = to;
}
</script>[/CODE]
Copy linkTweet thisAlerts:
@NeoboffinOct 09.2006 — I assumed you had Javascript knowledge. How are you trying to play these mp3 files. Through the user's media players on their desktops or through your web site?
Copy linkTweet thisAlerts:
@jamesx521authorOct 10.2006 — Right now what I have is:
[CODE]<a href="test.mp3" target="_blank">[/CODE] so it opens the file in whatever their IE, Mozzila, etc. native-audio-player is. I definitely need the [B]target="_blank"[/B] for the MP3, so that their audio-player doesn't open on the same window as the web page. And with the second [B]href[/B] I want that page to change to another page [B]target="_self"[/B].
Copy linkTweet thisAlerts:
@NeoboffinOct 10.2006 — Use this:

<a href="my_mp3.mp3" target="blank" onClick="window.location = 'http://yahoo.com/';">Play MP3</a>[/QUOTE]
Copy linkTweet thisAlerts:
@jamesx521authorOct 10.2006 — I forgot that my link is in an [B]iframe[/B] in the page, so for this part:
[CODE]onClick="window.location = 'http://yahoo.com/'[/CODE] I would need to add [B]target="_parent"[/B] somewhere: where? Thanks.
Copy linkTweet thisAlerts:
@NeoboffinOct 10.2006 — Give your IFrame a unique ID such as: id="myFrame"

Then change this: onClick="window.location = 'http://yahoo.com/';"

To: onClick="document.getElementById('myFrame').src = 'http://yahoo.com/';"
Copy linkTweet thisAlerts:
@jamesx521authorOct 10.2006 — I followed your directions [I]Neoboffin[/I] but it didn't work. I put [B]ID[/B] in the [B]iframe[/B] and used the new [B]onClick[/B] code too. The page doesn't change at all. In the previous version: [B]onClick="window.location = 'http://yahoo.com/';"[/B] the page [U]did[/U] change, except it was in the [B]iframe[/B]. Are there other solutions? Thanks.
Copy linkTweet thisAlerts:
@NeoboffinOct 10.2006 — Like this? -- It works for me.

<iframe id="myFrame" width="400" height="400"></iframe>

<a href="my_mp3.mp3" target="blank" onClick="document.getElementById('myFrame').src = 'http://yahoo.com/';">Play MP3</a>[/QUOTE]
Copy linkTweet thisAlerts:
@jamesx521authorOct 10.2006 — That's what I have, except with different names and links. My [B]iframe[/B] is placed within [B]<div></div>[/B]. Would that interfere anyhow?
Copy linkTweet thisAlerts:
@jamesx521authorOct 11.2006 — Do I still need this code in the iframe page:
[CODE]<script language="javascript" type="text/javascript">
function letsGo(play, to)
{
// Your MP3 plyer stuff here.

// Go to link
window.location = to;
}
</script>[/CODE]
when I use the two codes below... the first, in the main page that calls the iframe: [CODE]<iframe id="myFrame" width="400" height="400"></iframe>[/CODE] and this second, in the iframe page: [CODE]<a href="my_mp3.mp3" target="blank" onClick="document.getElementById('myFrame').src = 'http://yahoo.com/';">Play MP3</a>[/CODE]
Copy linkTweet thisAlerts:
@NeoboffinOct 12.2006 — No you don't need that javascript code on any page.

I'm not sure what your asking about the other stuff either.
×

Success!

Help @jamesx521 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.10,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...