LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-26-2008, 04:53 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
can javascript control the loop attribute of an embed object?


I have a video embedded on a webpage (using embed rather than object).

I'd like to put a button somewhere that will make the video loop or not loop.

I can change other attributes of the video (with a name of 'thevideo') like so:
Code:
document.embeds['thevideo'].width=400;
document.embeds['thevideo'].filename="some_file.mov";
but I can't seem to get to the loop attribute. Is it possible? If so, how? I've tried all the incarnations of:
Code:
document.embeds['thevideo'].loop=true;
I tried 1,true,"true","'true'" - none of which worked. No error in Firefox's error console, but no looping either.

Ideas?
 
Old 06-26-2008, 06:50 PM   #2
ewolf
LQ Newbie
 
Registered: Dec 2007
Location: Chicago, USA
Distribution: Debian, NetBSD
Posts: 25

Rep: Reputation: 15
If your element has an 'id' attribute set as follows,

Code:
<embed id='myEmbedObjectId'></embed>
then this should do it:

Code:
document.getElementById('myEmbedObjectId').setAttribute('loop','true');
I haven't tested it with an <embed> element, but it works for other kinds of elements and attributes.
 
Old 06-26-2008, 08:18 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by ewolf View Post
If your element has an 'id' attribute set as follows,

Code:
<embed id='myEmbedObjectId'></embed>
then this should do it:

Code:
document.getElementById('myEmbedObjectId').setAttribute('loop','true');
I haven't tested it with an <embed> element, but it works for other kinds of elements and attributes.
hmmm.. That does seem to set that attribute (verified by "viewing generated source" - thanks firefox web devloper plugins), so thanks for the tip (I had forgotten about setAttribute), but it doesn't force the video to go from non-looping to looping. I imagine this has something to do with the fact that the object is already loaded with the loop attribute set to false & does not get reloaded when the attribute changes.

There's probably a way to do that too, I'd imagine. I'm going to look into it, but if anyone knows how to make the embedded object respond to the new loop attribute, I'd love to know.
 
Old 06-27-2008, 10:09 AM   #4
ewolf
LQ Newbie
 
Registered: Dec 2007
Location: Chicago, USA
Distribution: Debian, NetBSD
Posts: 25

Rep: Reputation: 15
Quote:
Originally Posted by BrianK View Post
hmmm.. That does seem to set that attribute (verified by "viewing generated source" - thanks firefox web devloper plugins), so thanks for the tip (I had forgotten about setAttribute), but it doesn't force the video to go from non-looping to looping. I imagine this has something to do with the fact that the object is already loaded with the loop attribute set to false & does not get reloaded when the attribute changes.
I haven't dealt too much with embedded content like this, but the next thing I would try would be to do something like this:

Code:
<script type="text/javascript">
function changeLoopAttribute(wrapperId, loopAttribute) {
    var embedWrapper = document.getElementById(wrapperId);
    var myEmbed = document.createElement('embed');
    myEmbed.setAttribute('loop','true');
    // set your other attributes (filename, etc) here
    embedWrapper.parentNode.replaceChild(myEmbed, embedWrapper);
}

changeLoopAttribute('embeddedContentWrapper','true');
</script>

<div id='embeddedContentWrapper'><!-- your embed element will go here --></div>
If that doesn't work, you can try this:

Code:
function changeLoopAttribute(wrapperId, loopAttribute) {
    var embedWrapper = document.getElementById(wrapperId);
    embedWrapper.innerHTML = "<embed loop='" + loopAttribute + "' " + yourOtherAttributes + "></embed>";
}
Let me know if either of those work out for you.

Last edited by ewolf; 06-27-2008 at 10:12 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript object static method? gsbarry Programming 2 11-11-2006 06:36 AM
Real-time close loop control needs serial port communication areftaidi Linux - Software 6 01-25-2006 06:30 PM
PerlTK loose control in loop Atrocity Programming 1 05-10-2005 12:16 PM
Javascript error "is null or not an object" apt Programming 2 03-28-2005 06:14 AM
How can I tell one object to do a method in javascript? eantoranz Programming 1 10-29-2004 01:20 PM


All times are GMT -5. The time now is 04:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration