PDA

View Full Version : help with two popup and sound



mikez
11-17-2006, 11:44 PM
Hi all, first timer on here looking for some advice, help and whatever else you might want to throw my way. but please be gentle.

Question is, I have page that contains a few links on it (all internal) and I'm already using a javascript to launch a pop up window when user clicks on link. somehow i ended up with all the links being highlighted as well but i think thats due to a menu im using, i dont know, but i like it.everything is great but i was thinking adding a sound to that same link. that onmousever script would be perfect but i dont know hot to add that to existing. any ideas?

this is how im displaying my link.

<li><a href=javascript:popcontact('1.htm')><font face="Verdana" size="2">
Installations</font></a>
<li><a href=javascript:popcontact('2.htm')><font face="Verdana" size="2">
Repair</font></a>


thanks in advance..

jscheuer1
11-20-2006, 07:45 AM
What do you want the sound to do? Do you want it to play when the link is clicked (sound effect) or at some other time? Or, do you want a long sound file to commence playing?

In any case, using the javascript: convention is a poor choice, this is better:


<a href="1.htm" onclick="popcontact(this.href);return false;"><font face="Verdana" size="2">
Installations</font></a>

Once you have it broken out that way, you can add to the onclick event:


<a href="1.htm" onclick="popcontact(this.href);make_noise();return false;"><font face="Verdana" size="2">
Installations</font></a>

Or, add a different event:


<a href="1.htm" onclick="popcontact(this.href);return false;" onmouseover="make_noise();"><font face="Verdana" size="2">
Installations</font></a>

Notes: make_noise(); is just a name I made up. If you have an actual function to run, use its name.

mikez
11-20-2006, 09:40 PM
thanks jscheuer1.

to answer your question on what i want it to do. i want to play a slimmed down version of a click sound, nothing fancy or big just a little click effect so that user knows (if the highlight isnt enough) its a link. dont want any song, chorus or background music just a simple click when mouse moves over it and thats it.

if you dont mind me asking why is the javasript a bad idea? i thought that was the only way to do a pop up window but i guess not.

anyway thanks for the reply and i'll see what happens with using your code. thanks again.

jscheuer1
11-21-2006, 04:54 PM
thanks jscheuer1.

if you dont mind me asking why is the javasript a bad idea? i thought that was the only way to do a pop up window but i guess not.

It can lead to all sorts of problems. In many IE versions, it institutes page unload. This can mess up many things on the page where these types of links are, if (as in this case) clicking the link doesn't actually unload the page.

It makes it tougher to combine events.

That's the worst that I am aware of but, as a courtesy to non-javascript enabled browsers, there should generally be a real href on an anchor link. What this href is should be some sort of non-javascript alternative to what would otherwise (if different) happen when clicking the link in a javascript-enabled browser. Having a real link here also helps index your site. If no link is truly desired, then an anchor tag is inappropriate and javascript events can be attached to another element.

Berdusk
09-16-2007, 05:14 PM
Hey There,

I've actually got a similar problem, but my link is calling another application instead of another browser window. What I want is to make it play the sound file upon clicking the link as well as open up the other window.

I'm currently using this syntax:


<a href="telnet://berdusk.com:2223" onclick="playsound('ding2.wav');"><img src="BerduskBanner3.jpg" width="500" height="125" border="0" alt="Connect to Berdusk"></a>

If I change to onclick="playsound('ding2.wav');return false;" I am able to get my browser to play the sound file, but it doesn't open up Telnet.

If I change to onclick="playsound('ding2.wav');return true;" I am able to get my browser to open Telnet, but it won't play the sound file.

Currently, without using either one, I am sometimes able to catch the very beginning of the sound file before it cuts off and opens the application.

Any suggestions would be helpful. Thank you. :)

-Daniel

djr33
09-17-2007, 01:46 AM
You've narrowed down the problem well.

Seems like the problem is fairly simple. Once focus has shifted to the other app, the sound is no longer heard. In fact, I expect it DOES play, but just isn't heard when the window isn't focused.

That means you will need to decide-- do you want the sound to play or the telnet window to be focused?

I think the options here are pretty simple, though nothing jumps out as great.
1. Skip the sound.
2. Keep focus on the current window, using window.focus(). I think this should work, but it would place telnet behind the current window, then.
3. playsound(), until it's done, and THEN open the telnet window. Probably the best option, but this will delay the telnet page loading for the length of the audio, including loading.

Berdusk
09-17-2007, 07:04 AM
Okay. I kind of figured it had something to do with the browser no longer being the active window from the behavior above, but I didn't want to speak out of turn.

What changes would I need to make to the syntax above to make it so that it didn't load Telnet until after the sound file had played? Thanks for the help. :)

-Daniel
P.S. Thanks for the fast response. ^_^