Javascript 如何在将对象添加到DOM时激发函数

Javascript 如何在将对象添加到DOM时激发函数,javascript,events,dom,Javascript,Events,Dom,我想将视频添加到我的网站。他们提供了一个脚本文件,我必须在我的页面中链接它 // Copyright 2012 Website Talking Heads // JavaScript Document if (typeof wthvideo == "undefined") { wthvideo = new Object(); } wthvideo.params = { width:200, height:384, position:"fixed", doc

我想将视频添加到我的网站。他们提供了一个脚本文件,我必须在我的页面中链接它

// Copyright 2012 Website Talking Heads
// JavaScript Document
if (typeof wthvideo == "undefined") {
    wthvideo = new Object();
}
wthvideo.params = {
    width:200,
    height:384,
    position:"fixed",
    doctype:"strict",
    left:"50%",
    right:"auto",
    top:"140px",
    bottom:"auto",
    centeroffset:"-660px",
    color:0xCCCCCC,
    volume:70,
    autostart:"yes",
    fadein:0,
    fadeout:2,
    flip:"no",
    delay:0,
    delayclose:0,
    buffertime:3,
    controlbar:"yes",
    exitbtn:"no",
    playbtn:"PlayVideo.png",
    playposition:"center",
    playtop:"bottom",
    exitoncomplete:"yes",
    oncepersession:"no",
    vidlink:"no",
    openin:"_blank",
    path:"wthvideo",
    actorpic:"angiewasabiloco.png",
    flv:"angiewasabiloco.flv",
    h264:"angiewasabiloco.mp4",
    iactorpic:"angiewasabiloco.jpg",
    iwidth:200,
    iheight:384};

var topPx = parseFloat(wthvideo.params.top);
var bottomPx = parseFloat(wthvideo.params.bottom);

wthvideo.hideDiv = function(){
    document.getElementById('wthvideo').style.visibility = 'hidden';
}
function onlyOnce() {
if (document.cookie.indexOf("hasSeen=true") == -1) {
var later = new Date();
later.setFullYear(later.getFullYear()+10);
document.cookie = 'hasSeen=true;path=/;';
wthvideo.drawVideo();
}
}
function onlyOnce2() {
if (document.cookie.indexOf("hasSeen=true") == -1) {
var later = new Date();
later.setFullYear(later.getFullYear()+10);
document.cookie = 'hasSeen=true;path=/;';
wthvideo.drawVideo();
}
}

wthvideo.drawVideo= function(){
    var markUp = '';
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    if(isiPad || navigator.platform == 'iPad' || navigator.platform == 'iPhone'|| navigator.platform == 'iPod' ) {
        markUp += '<style type="text/css">';
        markUp += '#wthvideo {position:'+wthvideo.params.position+';width:'+wthvideo.params.iwidth+'px;height:'+wthvideo.params.iheight+'px;margin-left:-100px;left:'+wthvideo.params.left+';right:'+wthvideo.params.right+';top:40px;bottom:'+wthvideo.params.bottom+';z-index:99999;}';
        markUp += '</style>';
        markUp += '<div id="wthvideo">';
        markUp += '<video poster="'+wthvideo.params.path+'/'+wthvideo.params.iactorpic+'" controls="controls" width="'+wthvideo.params.iwidth+'" height="'+wthvideo.params.iheight+'">';
        markUp += '<source src="'+wthvideo.params.path+'/'+wthvideo.params.h264+'" type="video/mp4" />';
        markUp += '</video>';
        markUp += '</div>';
}
else {
    markUp += '<style type="text/css">';
    markUp += '#wthvideo {position:'+wthvideo.params.position+';width:'+wthvideo.params.width+'px;height:'+wthvideo.params.height+'px;margin-left:'+wthvideo.params.centeroffset+';left:'+wthvideo.params.left+';right:'+wthvideo.params.right+';top:'+wthvideo.params.top+';bottom:'+wthvideo.params.bottom+';z-index:99999;}';
    markUp += '</style>';
    markUp += '<div id="wthvideo">';
    markUp += '  <object id="objvideo" style="outline:none;" type="application/x-shockwave-flash" width="'+wthvideo.params.width+'" height="'+wthvideo.params.height+'" data="'+wthvideo.params.path+'/wthplayer.swf">';
    markUp += '    <param name="movie" value="'+wthvideo.params.path+'/wthplayer.swf" />';
    markUp += '    <param name="quality" value="high" />';
    markUp += '    <param name="flashvars" value="vurl='+wthvideo.params.flv+'&amp;vwidth='+wthvideo.params.width+'&amp;vheight='+wthvideo.params.height+'&amp;actorpic='+wthvideo.params.path+'/'+wthvideo.params.actorpic+'&amp;autostart='+wthvideo.params.autostart+'&amp;exitoncomplete='+wthvideo.params.exitoncomplete+'&amp;vbuff='+wthvideo.params.buffertime+'&amp;vdelay='+wthvideo.params.delay+'&amp;vcolor='+wthvideo.params.color+'&amp;vlink='+wthvideo.params.vidlink+'&amp;openin='+wthvideo.params.openin+'&amp;delayclose='+wthvideo.params.delayclose+'&amp;fadein='+wthvideo.params.fadein+'&amp;fadeout='+wthvideo.params.fadeout+'&amp;vvol='+wthvideo.params.volume+'&amp;playbtn='+wthvideo.params.path+'/'+wthvideo.params.playbtn+'&amp;playpos='+wthvideo.params.playposition+'&amp;playtop='+wthvideo.params.playtop+'&amp;hflip='+wthvideo.params.flip+'&amp;controlbar='+wthvideo.params.controlbar+'&amp;exitbtn='+wthvideo.params.exitbtn+'" />';
    markUp += '    <param name="wmode" value="transparent" />';
    markUp += '    <param name="allowscriptaccess" value="always" />';
    markUp += '    <param name="swfversion" value="9.0.45.0" />';
    markUp += '  </object>';
    markUp += '</div>';
    if (wthvideo.params.position == "fixed") {
        if (wthvideo.params.doctype == "quirks") {
            if (wthvideo.params.top == "auto") {
                        markUp += '<!--[if IE]>';
                        markUp += '<style type="text/css">';
                        markUp += '#wthvideo {position:absolute; top: expression(offsetParent.scrollTop - 1 + (offsetParent.clientHeight-this.clientHeight) + '+bottomPx+' + "px")}';
                        markUp += '</style>';
                        markUp += '<![endif]-->';}
                    else {
                            markUp += '<!--[if IE]>';
                            markUp += '<style type="text/css">';
                            markUp += '#wthvideo {position: absolute !important;top: expression(((document.documentElement.scrollTop || document.body.scrollTop) + (!this.offsetHeight && 0)) + '+topPx+' + "px")';
                            markUp += '</style>';
                            markUp += '<![endif]-->';}
                    }
                else {
                        markUp += '<!--[if lte IE 6]>';
                        markUp += '<style type="text/css">';
                        markUp += 'html, body{height: 100%;overflow: auto;}#wthvideo {position: absolute;}';
                        markUp += '</style>';
                        markUp += '<![endif]-->';
            }
        }
    }

document.write(markUp);


}
function hideDiv() {
    wthvideo.hideDiv();
}

if (wthvideo.params.autostart=="oncethenpic") {
    if (document.cookie.indexOf("hasSeen=true") == -1) {
        var later = new Date();
        later.setFullYear(later.getFullYear()+10);
        document.cookie = 'hasSeen=true;path=/;';
        wthvideo.params.autostart = "yes";
        }
    else {
        wthvideo.params.autostart = "no";

    }
}

if (wthvideo.params.autostart=="oncethenmute") {
    if (document.cookie.indexOf("hasSeen=true") == -1) {
        var later = new Date();
        later.setFullYear(later.getFullYear()+10);
        document.cookie = 'hasSeen=true;path=/;';
        wthvideo.params.autostart = "yes";
        }
    else {
        wthvideo.params.autostart = "mute";
    }
}

if (wthvideo.params.autostart=="onceonly") {
    if (document.cookie.indexOf("hasSeen=true") == -1) {
        var later = new Date();
        later.setFullYear(later.getFullYear()+10);
        document.cookie = 'hasSeen=true;expires='+later.toGMTString();
        wthvideo.params.autostart = "yes";
        }
    else {
        wthvideo.params.autostart = "mute";
    }
}

if (wthvideo.params.autostart=="onceonlythenmute") {
    if (document.cookie.indexOf("hasSeen=true") == -1) {
        var later = new Date();
        later.setFullYear(later.getFullYear()+10);
        document.cookie = 'hasSeen=true;expires='+later.toGMTString();
        wthvideo.params.autostart = "yes";
        }
    else {
        wthvideo.params.autostart = "mute";
    }
}
if (wthvideo.params.autostart=="onceonlythenpic") {
    if (document.cookie.indexOf("hasSeen=true") == -1) {
        var later = new Date();
        later.setFullYear(later.getFullYear()+10);
        document.cookie = 'hasSeen=true;expires='+later.toGMTString();
        wthvideo.params.autostart = "yes";
        }
    else {
        wthvideo.params.autostart = "no";

    }
}

if (wthvideo.params.oncepersession == "yes") {
    onlyOnce();}
    else {
        if (wthvideo.params.oncepersession == "onceonly") {
            onlyOnce2();}
        else {
        wthvideo.drawVideo();
    }
    }


function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }

function exitWTH() {
    thisMovie('objvideo').exitVideoWTH();
}
function pauseWTH() {
    thisMovie('objvideo').pauseVideoWTH();
}

function unpauseWTH() {
    thisMovie('objvideo').unpauseVideoWTH();
}
function playWTH() {
    thisMovie('objvideo').playVideoWTH();
}
function stopWTH() {
    thisMovie('objvideo').stopVideoWTH();
}
function muteWTH() {
    thisMovie('objvideo').muteVolWTH();
}
function unmuteWTH() {
    thisMovie('objvideo').startVolWTH();
}
function cue0() {
    pauseWTH();
}
//版权所有2012网站Talking Heads
//JavaScript文档
如果(wthvideo的类型==“未定义”){
wthvideo=新对象();
}
wthvideo.params={
宽度:200,
身高:384,
位置:“固定”,
doctype:“严格”,
左:“50%”,
右:“自动”,
顶部:“140px”,
底部:“自动”,
中心偏移量:“-660px”,
颜色:0xCCCC,
卷:70,
自动启动:“是”,
法登:0,
淡出:2,
翻转:“不”,
延迟:0,
延迟关闭:0,
缓冲时间:3,
控制栏:“是的”,
出口:“否”,
playbtn:“PlayVideo.png”,
游戏位置:“中锋”,
playtop:“底部”,
exitoncomplete:“是”,
oncepersession:“否”,
视频链接:“否”,
openin:“_blank”,
路径:“wthvideo”,
actorpic:“angiewasabiloco.png”,
flv:“angiewasabiloco.flv”,
h264:“angiewasabiloco.mp4”,
iactorpic:“angiewasabiloco.jpg”,
我宽:200,
iheight:384};
var topPx=parseFloat(wthvideo.params.top);
var bottomPx=parseFloat(wthvideo.params.bottom);
wthvideo.hideDiv=函数(){
document.getElementById('wthvideo').style.visibility='hidden';
}
函数onlyOnce(){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;path=/;';
wthvideo.drawVideo();
}
}
函数onlyOnce2(){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;path=/;';
wthvideo.drawVideo();
}
}
wthvideo.drawVideo=函数(){
var标记=“”;
var isiPad=navigator.userAgent.match(/iPad/i)!=null;
如果(isiPad | | | navigator.platform==“iPad”| | navigator.platform==“iPhone”| | navigator.platform==“iPod”){
标记+='';
标记+='#wthvideo{position:'+wthvideo.params.position+';宽度:'+wthvideo.params.iwidth+'px;高度:'+wthvideo.params.iheight+'px;左边距:-100px;左边:'+wthvideo.params.left+';右边:'+wthvideo.params.right+';顶部:40px;底部:'+wthvideo.params.bottom+'z-index:9999;};
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
}
否则{
标记+='';
标记+='#wthvideo{position:'+wthvideo.params.position+';宽度:'+wthvideo.params.width+'px;高度:'+wthvideo.params.height+'px;左边距:'+wthvideo.params.centeroffset+';左:'+wthvideo.params.left+';右:'+wthvideo.params.right+';顶部:'+wthvideo.params.top+';底部:'+wthvideo.params.bottom+'99;';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
标记+='';
如果(wthvideo.params.position==“固定”){
if(wthvideo.params.doctype==“怪癖”){
如果(wthvideo.params.top==“自动”){
标记+='';}
否则{
标记+='';}
}
否则{
标记+='';
}
}
}
文件。编写(标记);
}
函数hideDiv(){
wthvideo.hideDiv();
}
if(wthvideo.params.autostart==“oncethenpic”){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;path=/;';
wthvideo.params.autostart=“是”;
}
否则{
wthvideo.params.autostart=“否”;
}
}
if(wthvideo.params.autostart==“oncethenmute”){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;path=/;';
wthvideo.params.autostart=“是”;
}
否则{
wthvideo.params.autostart=“静音”;
}
}
if(wthvideo.params.autostart==“onceonly”){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;expires='+later.togmString();
wthvideo.params.autostart=“是”;
}
否则{
wthvideo.params.autostart=“静音”;
}
}
if(wthvideo.params.autostart==“onceonlythenmute”){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;expires='+later.togmString();
wthvideo.params.autostart=“是”;
}
否则{
wthvideo.params.autostart=“静音”;
}
}
if(wthvideo.params.autostart==“onceonlythenpic”){
if(document.cookie.indexOf(“hasSeen=true”)=-1){
var later=新日期();
later.setFullYear(later.getFullYear()+10);
document.cookie='hasSeen=true;expires='+later.togmString();
wthvideo.params.autostart=“是”;
}
否则{
wthvideo.params.autostart=“否”;
}
}
如果(wthvideo.params.oncepersession==“是”){
onlyOnce();}
否则{
if(wthvideo.params.oncepersession==“onceonly”){
onlyOnce2();}
否则{
wthvideo.drawVideo();
}
}
函数thisMovie(movieName){
if(navigator.appName.indexOf(“Microsoft”)!=-1){
返回窗口[movieName];
}否则{
归还文件[movieName];
}
}
函数exitWTH(){
thisMovie('objvideo')。exitVideoWTH();
}
函数pauseWTH(){
这部电影('objvideo')。pauseVideoWTH();
}
函数unpauseWTH(){
此电影('objvideo')。取消暂停();
}
函数playWTH(){
这部电影('objvideo')。播放视频();
}
函数stopWTH(){
thisMovie('objvideo')。stopVideoWTH();
}
函数muteWTH(){
thisMovie('objvideo')。muteVolWTH();
}
functi
$('.wthvideo').livequery(function(){
    //Do your stuff here
});