Debt Consolidation - Submit articles - vBulletin - Kamala Harris - Debt Consolidation

PDA

View Full Version : dynamically change src on embed tag?


bigalc
May 10th 2006, 6:10 am
Hi there

I've been using a piece of code accross a number of my sites for a while that toggles displayed images by changing the src of an img tag. I assumed it would work fine with the embed tag too, but it seems it doesn't. Any ideas?


//on head:

function loadmov(moviename) {
document.embeds['movieid'].src = ("../path/"+ moviename);
focus();
}


//on icon:

onClick="loadmov('mymovie')"

naturaldesigns
May 10th 2006, 9:14 am
you can make it this way:



//on head:

function loadmov(moviename) {
document.embeds['movieid'].src = ("<?php echo $file; ?>");
focus();
}


//on icon:

onClick="loadmov('mymovie')"



then you have to declare the variable (I assume you kno how....otherwise ask or google) and remember that you have to escape all special characters...read more here: www.zend.com/zend/tut/using-strings.php


greets

bigalc
May 11th 2006, 3:53 am
Thanks a lot for your reply.

Could you explain a little more? Why do I need to use php to declare the filename- I don't really understand why it doesn't work in the same way as it does for the img tag. :confused:

Any help would be really appreciated!

naturaldesigns
May 11th 2006, 6:12 am
Oh I think I missunderstood your needs...with the word dynamically I thought you wanted to display something depending on which site you are for example without always having to rewrite the embed tag etc...

Can you explain the problem once again a little better?

greets

Cypherswipe
Nov 16th 2008, 3:53 pm
I stumbled on this thread from a web search. I think he was trying to do the same thing I'm trying to do, and that is to duplicate the effect of the target attribute in an anchor tag. For example, you can "embed" a movie in a page using an iframe, then have links on the page to watch different clips & have them open in the iframe simply by setting the target attribute to target the iframe's ID. Unfortunately, neither embed nor object tags can be targetted in such a way. To achieve the same effect with an embed or object tag, you need to use javascript to change the src attribute of the embed tag when you click the appropriate link.
I have found a few snippets of code online that -should- work for this, but can't get any to actually work. Here's a sample page I've uploaded, the 2 "test" links are the codes I've grabbed from the web. ht-tp://allspark.net/cypherswipe/js-embed-src.html Absolutely nothing happens when I click either test link.

As you can tell from the other links on the page, I was originally using an iframe tag + target attributes. That no longer works however, as when you try to view the vids directly, the player is downloaded instead of playing in the browser (it appears that mogulus is now delivering the player with a binary/octet mime type, which causes the browser to save it unless it's embedded in an embed or object tag).


This is for a local file for my own use btw, so it has to be javascript, not anything server-side like php.