Click to See Complete Forum and Search --> : Help with JavaScript + Embed src Code


Four_of_Five
09-26-2003, 11:56 AM
I'm trying to have an avi file open up on a "Tv-Screen" within the same webpage (inside a single table cell, same spot) when a particular button/link is clicked (and changed accordingly whenever a different button/link is clicked). If you want to read how the whole thread started out Click Here (http://forums.webdeveloper.com/showthread.php?s=&postid=95810#post95810)

Otherwise here's the JavaScript "solution" I got (which unfortunately, i'm still too dumb to figure out the rest of the body code): Hope someone can help me out.

Originally posted by PunkSktBrdr01
Well, if you want to use multiple videos, you could make a page for each one, or you could use JavaScript. I think this might work:

code:--------------------------------------------------------------------------------
<script type="text/javascript">
funtion changeChannel(channel) {
document.tv_screen.src = channel;
}
</script>
--------------------------------------------------------------------------------


Put that in the head of the page. Then add name="tv_screen" to the embed tag. In each link that will change the video, change the href to '#' and add onClick="changeChannel('video file name');". I think that's what you're looking for.

Jona
09-26-2003, 01:07 PM
Something along these lines would probably work better and for more than just the IE browser...


<script type="text/javascript"><!--
function changeChannel(channel){
if(document.getElementById){
document.getElementById("tv_screen").src=channel;
}
--></script>
</head>
<body>
<p><a href="jsDisabled.html" onclick="changeChannel('movie2.avi'); return false;">Movie 2</a> &middot;
<a href="jsDisabled.html" onclick="changeChannel('movie3.avi'); return false;">Movie 3</a></p>
<div>
<embed id="tv_screen" src="movie1.avi"></embed>
</div></body>
</html>


jsDisabled.html should be a simple page that says the person has no JavaScript enabled, and therefore must select one of the following different pages to see the movies (and create a document with the src = whichever movie that corresponds with the selected page/link). That way those without JavaScript will be able to see the movies as well.

[J]ona

Four_of_Five
09-26-2003, 02:06 PM
Thanks....but....well, it didn't work :(. Everytime I clicked on the "link"...it just launched the jsDisabled.html file, instead of playing the avi movie file on the embeded "tv screen".

I also tried "combining" some of the coding from the previous javascript but didn't work also...I changed the a href="#" and tried "bookmarking" the "tv screen" but didnt work either...just caused a nasty page fault.

Got any more ideas?

Jona
09-26-2003, 02:12 PM
The only time you'd be redirected to jsDisabled.html is if you didn't include the return false; part at the end, or your Javascript is disabled...

[J]ona

Four_of_Five
09-26-2003, 02:26 PM
Originally posted by Jona
The only time you'd be redirected to jsDisabled.html is if you didn't include the return false; part at the end, or your Javascript is disabled...

[J]ona

Nope. I'm pretty sure that i had included the return false part..(coz I had basically copied&pasted the body part) and my JavaScript is enabled (in fact, my entire webpage(s) are riddled with them :) and most of em work fine...except for this one :( Darn, and it seemed so promising

And, I don't think there are/should be any conflicts with other scripts coz I tried your script on stand-alone...so it essentially was pretty much a virgin before I uhmm..messed it up :p

Jona
09-26-2003, 02:33 PM
Well, it's basically the same concept as the playMid() script on this page (http://geocities.com/god_loves_07/next_mid.html).

[J]ona

Four_of_Five
09-26-2003, 03:01 PM
Originally posted by Jona
Well, it's basically the same concept as the playMid() script on this page (http://geocities.com/god_loves_07/next_mid.html).

[J]ona

Hmmmm...well, in so far as cycling through different media titles, I guess you're right. But, getting a sound file to play and change into another one on click is quite different from displaying a video file in the same place (and size) on the same webpage.

Oh yeah, I forgot to mention in your suggested script i added: autostart="false" after the src="somemovie.avi"...in which case there's an error:

Line: 9 Char: 1
Error: Expected '}'

What do you think I should do?

Jona
09-26-2003, 03:04 PM
Ah, this is the second time I've made this mistake today! :mad: Here we go...


<script type="text/javascript"><!--
function changeChannel(channel){
if(document.getElementById){
document.getElementById("tv_screen").src=channel;
} }
--></script>
</head>
<body>
<p><a href="jsDisabled.html" onclick="changeChannel('movie2.avi'); return false;">Movie 2</a> ·
<a href="jsDisabled.html" onclick="changeChannel('movie3.avi'); return false;">Movie 3</a></p>
<div>
<embed id="tv_screen" src="movie1.avi"></embed>
</div></body>
</html>


[J]ona

Four_of_Five
09-26-2003, 03:28 PM
Originally posted by Jona
Ah, this is the second time I've made this mistake today! :mad: Here we go...

[font=monospace]
<script type="text/javascript"><!--
function changeChannel(channel){
if(document.getElementById){
document.getElementById("tv_screen").src=channel;
} }
--></script>
[J]ona

hehehe :p sorry, but already done that...
Close but still No Dice :(

the good news though is that, it doesn't launch the jsdisabled.html file anymore...actually, when I click on any of the links...it doesnt do anything at all....arrrrgh..this is so :mad:

thanks so much for trying though...i think this calls for some Flash i think i found something similar to this at: PRELOADED (http://www.preloaded.com/v2/indexnorm.html)...the problem is that it ain't easy and the coding may kill me :D, that, and not all of my "clients" have Flash...

Jona
09-26-2003, 03:31 PM
I do not have three video files on my computer, so I cannot test the script on my computer; that is why I have been of little assistance. Good luck with whatever you decide to do.

[J]ona

Four_of_Five
09-26-2003, 04:16 PM
Really:confused: you have no .wma or avi files whatsover???

Well, I was just about to suggest that you try Quicktime movies (.MOV) and just rename them...then I stumbled upon another related problem: QTplayer doesn't seem to embed itself on the webpage :( unlike WindowsMedia

Oh well...the only thing i'm gonna do right now is catch some Zzzzzzzz

Jona
09-26-2003, 04:21 PM
Quicktime... Pff, I hate Quicktime. I downloaded Quicktime onto my Windows 98 computer, and I had to get rid of that 98 computer afterwards. It ruined the whole computer. I don't trust Apple with my PC's. :p

Anyways, embedding the video in Flash would actually be a very good alternative (makes it look much nicer, too).

[J]ona