I can't make this Javascript work in IE

Discussion in 'JavaScript' started by frostgiant, Jun 17, 2008.

  1. #1
    Hi. I am working on a script that is part of displaying a video feed on a web page (with php and javascript). I design on a linux machine running firefox. For the last few days I have been trying to figure out how to make this work in IE. There is something wrong, but I can't make stupid Internet Explorer to give me any sensible error messages:confused:.

    var my_div = null;
    var newObject = null;
    var newParam = null;
    var newEmbed = null;
    var d = null;
    var element = null;
    var id = null;
    var autoPlay = null;

    function getBrowserName() {
    var browserName = "";

    var ua = navigator.userAgent.toLowerCase();
    if ( ua.indexOf( "opera" ) != -1 ) {
    browserName = "opera";
    } else if ( ua.indexOf( "msie" ) != -1 ) {
    browserName = "msie";
    } else if ( ua.indexOf( "safari" ) != -1 ) {
    browserName = "safari";
    } else if ( ua.indexOf( "mozilla" ) != -1 ) {
    if ( ua.indexOf( "firefox" ) != -1 ) {
    browserName = "firefox";
    } else {
    browserName = "mozilla";
    }
    }

    return browserName;
    };

    function showMovie(id, autoPlay) {

    if (document.getElementById("movie")) {
    this.removeMovie("movie");
    }

    var browser = this.getBrowserName();

    newObject = document.createElement("object");
    newObject.setAttribute("id","movie");
    newObject.setAttribute("height","$height");
    newObject.setAttribute("width","$width");

    newParam = document.createElement("param");
    newParam.setAttribute("name","movie");
    newParam.setAttribute("value", "http://www.youtube.com/v/"+id+"&autoplay="+autoPlay+"&hl=en");
    newParam2 = document.createElement("param");
    newParam2.setAttribute("name", "wmode");
    newParam2.setAttribute("value", "transparent");

    newEmbed = document.createElement("embed");
    newEmbed.setAttribute("src", "http://www.youtube.com/v/"+id+"&autoplay="+autoPlay+"&hl=en");
    newEmbed.setAttribute("type","application/x-shockwave-flash")
    newEmbed.setAttribute("wmode", "transparent");
    newEmbed.setAttribute("height", "$height");
    newEmbed.setAttribute("width", "$width");

    my_div = document.getElementById("parent");
    my_div.appendChild(newObject);
    newObject.appendChild(newParam);
    newObject.appendChild(newParam2);
    newObject.appendChild(newEmbed);
    }

    function removeMovie(element)
    {
    var browser = this.getBrowserName();
    object = document.getElementById("movie");

    if (browser == "firefox" || browser == "mozilla" || browser == "opera" || browser == "safari")
    {
    while (object.childNodes[0])
    {
    object.removeChild(object.childNodes[0]);
    }
    }

    if (browser =="msie")
    {
    object.removeNode(true);
    }
    }
     
    frostgiant, Jun 17, 2008 IP
  2. frostgiant

    frostgiant Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok, so I got myself Microsoft Script Debugger to help me trace errors in Internet Explorer. Turns out IE is kicking on my dynamic creation of an <embed> tag. I'll try to hard-code the video element tags, and append them instead. If I get it to work I'll post what I did for reference :)
     
    frostgiant, Jun 18, 2008 IP
  3. frostgiant

    frostgiant Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have hardcoded something like this in HTML:
    <object id="movie">
    <param id="movieinfo"></param>
    <param id="wmode" value="transparent"></param>
    <embed id="embed" type="application/x-shockwave-flash" wmode="transparent"></embed>
    </object>


    Then I e. g. tried to do this with javascript:
    newObject = document.getElementById("movie");
    newEmbed = document.getElementById("embed");
    newEmbed.setAttribute("src", "http://www.youtube.com/v/"+id+"&amp;autoplay="+autoPlay+"&amp;hl=en");
    newEmbed.setAttribute("height", "$height");
    newEmbed.setAttribute("width", "$width");

    my_div = document.getElementById("parent");
    my_div.appendChild(newObject);
    newObject.appendChild(newEmbed);


    ...which obviously didn't work. How can I do this? What I want to do is make for instance the embed tag that I hardcoded from <embed id="embed"></embed> into <embed id="embed" src="http://mynicesource.com"></embed> without having to make the tag itself, because IE returns an error if I do, but I'm thinking I might work around it by just adding to the existing tag. Does this make any sense? :)
     
    frostgiant, Jun 18, 2008 IP
  4. frostgiant

    frostgiant Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Erm... nevermind... I'm such a noob :-D

    Of course, all I had to do was
    src = newEmbed.setAttribute("src","http://www.whatever.com");
    newEmbed.appendchild("src")

    for instance.

    So thank you me for answering my question. Oh, don't mention it.
     
    frostgiant, Jun 19, 2008 IP
  5. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    LOL :p :D

    ...
     
    MMJ, Jun 19, 2008 IP