YouTube Videos & passing Code as Strings.

Discussion in 'JavaScript' started by RogerDodgr, Jan 18, 2010.

  1. #1
    Hello,

    I'm trying to create a function that allows:
    writers for my site to insert video code like YouTube embed code (and others) into a javascript anchor-tag snippet. The writers (or myself) would copy paste an anchor tag (see below), and then copy and paste the video code inside of that anchor-tag snippet.

    
    <A HREF="javascript:insert('
    <object width=\'425\' height=\'344\'>.....</embed></object>
    ', 'ggPara1')"> videoTest</a> 
    
    ...
    
    <div id="ggPara1"></div>
    
    Code (markup):
    The above code works, but there is a problem. The writer will have to go through the entire video/embed code and replace every quotation mark (") with backslash and single quotation mark (\'). This is a pain in the neck.

    The anchor tag calls a simple function that uses DOM to write the string t oa div tag (the div tag is also passed as a parameter)
    
    function insert(s, tag){
            document.getElementById(tag).innerHTML = s;
    }
    
    Code (markup):
    There are several other video sources (besides youtube), and I don't want to write another function for each video. The problem, as I see it, is passing code as a string and all the problems with specific characters.
     
    Last edited: Jan 18, 2010
    RogerDodgr, Jan 18, 2010 IP