Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: <embed> src

  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question <embed> src

    Hello,

    I tried everything possible i knew.
    I followed the articles that some people pointed to me.
    I was also searching by myself too. I came with nothing so, i am starting agonize.

    all i need is to access and change the "src" attribute inside the <embed></embed> object
    I thought i can pick it up like any other element (from its id or the tag name) that’s not case.
    Say If I have an embed tag as it follows:

    Code:
    <embed src="" id="thePlayer" …. ></embed>
    I believed that this line will do exactly what I need
    Code:
    document.getElementById('thePlayer').src = path;
    But it won't work
    i can only guess that it matters that i have put embed inside <object> that works very well but only in IE so it’s probably considered as nested element or something
    maybe i need to refer 1st the <object> and then the embed but i have no clue how.

    Help I need somebody help … Beatles lol

    P.S. i am using ASp.NET 2.0 as server-side code if it can help at all

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts
    <marquee>thanks</marquee>

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The "embed" tag may not allow that. What you may have to do instead is place the tag into a div, and then use JavaScript to completely rewrite the contents of the div. Research ".innerHTML".
    Chris, thanks for the link.
    but I am afraid it is not very helpful as i am not a javascript guru. lol
    so, it's nothing but one more confusion for me.

    hmmm ... I was wondering if someone (JS guru) can improvise over the given explanation above?!

    Thanks in advance

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts
    hi there you will need to change the embed tag with innerHtml

    wrapper = document.getElementById('mysound-wrapper');
    wrapper.innerHTML = '<embed src="a_new_song_.mp3">';

    <div id="'mysound-wrapper">
    <embed src="a_song_.mp3">
    </div>

    here is some code below that night help....


    <html>
    <head>
    <script>
    var songs = new Array(
    "http://www.boutell.com/boutell/a.mp3",
    "Song Title A",
    "http://www.boutell.com/boutell/b.mp3",
    "Song Title B",
    "http://www.boutell.com/boutell/c.mp3",
    "Song Title C",
    "http://www.boutell.com/boutell/d.mp3",
    "Song Title D"
    );

    function switchSongs(i)
    {
    var file = songs[i * 2];
    var title = songs[i * 2 + 1];
    var element = document.getElementById('mysound_wrapper');
    element.innerHTML = embedSound(file);
    var element = document.getElementById('songtitle');
    element.innerHTML = title;
    var selector = document.getElementById('song_selector');
    selector.selectedIndex = i;
    return;
    }

    function embedSound(sound)
    {
    return '<embed src="' + sound + '" autostart="true" ' +
    'width="320" height="32">';
    }
    </script>
    </head>
    <body onLoad="switchSongs(0)">
    <h1 align="center">music</h1>
    <div align="center">
    <select name="song_selector" id="song_selector"
    onChange="switchSongs(selectedIndex)">
    <script>
    for (i = 0; (i < songs.length); i += 2) {
    var file = songs[i];
    var title = songs[i + 1];
    document.write('<option value="' +
    i + '">' +
    title + '</option>\n');
    }
    </script>
    </select>
    <p>
    <h4>Now Playing: <span id="songtitle"></span></h4>
    <p>
    <div id="mysound_wrapper">
    <noscript>
    Our music player requires that you enable JavaScript in your
    web browser's preferences.
    </noscript>
    </div>
    </div>
    </body>
    </html>
    <marquee>thanks</marquee>

  • #5
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it makes sense to me ... however i will need to try that before i say anything.
    Thanks for the code and also thanks for your time Chris.
    It is highly appreciated.

  • #6
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Buddy it is perfection. Althrough for you maight be simple for me this is solution for my big problem. Thanks a billion. Now i see that i should not understimate the javascript. Shame on me

    Regards

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts
    hey drmak.. i find javascript takes you to the darkside... for me also its still a world of confusion..

    its like watching donnie darko,, you think you have got it, then it just confuses you again...

    peace
    <marquee>thanks</marquee>

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If you want it to work in standard compliant browsers you should use <object> instead of the proprietary (non-standard) <embed> tag.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok i am open for suggestion. Actually before this i tried with the object tag so it worked properly only in IE while in FireFox it wasn't appearing at all.
    Can you please provide an example of using object that will work for FF too?
    Thanks in advance


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •