0

so I am trying to use document.write to write anohter script to the document. Here is my code for the function:

    function onSaveOk(streamName,streamDuration,userId,cameraName,micName,recorderId){
        //alert("onSaveOk("+streamName+","+streamDuration+","+userId+","+cameraName+","+micName+")");

        //the user pressed the [save] button inside the recorder and the save_video_to_db.XXX script returned save=ok
        //recorderId: the recorderId sent via flash vars, to be used when there are many recorders on the same web page


            $('#record').hide();

document.write('"<d"+"iv id=jwplayer>"
+ "<cen"+"ter>" +
"<d"+"iv id=mediaplayer>"+"</di"+"v>"+
"<scr"+"ipt type=text/javascript>
  jwplayer('mediaplayer').setup({
    'flashplayer': 'jwplayer/player.swf',
    'id': 'playerID',
    'width': '640',
    'height': '580',
    'provider': 'rtmp',
    'streamer': 'rtmp://domain/recorder/_definst_',
    'file': 'onSaveOk("+streamName+")'
  }); " +
"</scr"+"ipt>"+
"</cen"+"ter>"
')

Basically what happens is the recorder that was suposed to show up simply does not show up. When I have this in my function, for some reason $('#record').hide(); doesnt work eiether...

5
  • 1
    You need to learn Javasscript and jQuery, in that order. Commented Oct 10, 2012 at 1:56
  • Why do you need to write a script dynamically that way? It looks like you could just include the script Commented Oct 10, 2012 at 1:59
  • @Yatrix Because the variable onSaveOk("+streamName+")' is not declared until the function onSaveOk is called, so it needs to run after that. Commented Oct 10, 2012 at 1:59
  • No, it grabs a variable from the flash element. Commented Oct 10, 2012 at 2:05
  • Your quotes are very confusing, are you sure you want to encapsule the whole thing in ' and still use unescaped 'inside? Commented Oct 10, 2012 at 2:50

2 Answers 2

1

You should append the <div> using jQuery directly, and call the function normally.

Sign up to request clarification or add additional context in comments.

Comments

0

Once the document has been parsed, you do not use document.write() as it will clear the current document. Instead, you need to programatically add elements to your document.

To add your HTML to your document after it has been loaded, you could use this javascript:

var player = document.createElement("div");
player.innerHTML = '<div id="mediaplayer"></div>';
player.id = "jwplayer";
document.body.appendChild(player);    // you decide where to add it to your page

jwplayer('mediaplayer').setup({
    'flashplayer': 'jwplayer/player.swf',
    'id': 'playerID',     // shouldn't this match one of the IDs in your HTML???
    'width': '640',
    'height': '580',
    'provider': 'rtmp',
    'streamer': 'rtmp://domain/recorder/_definst_',
    'file': 'onSaveOk("+streamName+")'
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.