Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Javascript Basics for Advertisers

1,215 views

Published on

  • Be the first to comment

  • Be the first to like this

Javascript Basics for Advertisers

  1. 1. Javascript for Advertisers
  2. 2. History Lesson -Netscape Navigator ( Live Script then later Javascript ) -Internet Explorer ( VbScript then later Jscript ) Early 1990’s 1996 - ECMAScript or ECMA-262
  3. 3. Browser Wars
  4. 4. Why Javascript? -Language of the Web -Huge install base -Very expressive -Very flexible -Universally Hated!
  5. 5. Javascript Basics Variables var iAmALocalVariable = "hello"; iAmAGlobalVariable = "hello world";
  6. 6. Javascript Basics Functions function iSayHello(){ alert("hello"); }
  7. 7. Javascript Basics Parameters function iSayHelloToYou(name){ alert("hello "+name); }
  8. 8. Javascript Basics Flow Control if( theWorldIsAboutToEnd ){ alert("Panic!"); }else{ alert("Have a nice cup of tea and a sit down"); }
  9. 9. Javascript Basics Loops for( var counter = 0; counter < 10; counter+=1 ){ alert("counter is at: "+counter); }
  10. 10. Javascript Basics document.write("<img src='trackingImage.gif'/>"); Element.onclick= callFunctionHere; Broswer Interaction
  11. 11. Tracking Example Scripts <script src="%h/879366/flashwrite_1_2.js"></script> <SCRIPT LANGUAGE="JavaScript">…
  12. 12. Tracking Example Function and Variable Declarations function DCFlash(id,pVM){ var swf = "%h/1436076/LW_gifting_728x90.swf"; var gif = "%h/1436076/LW_gifting_728x90.gif"; var minV = 8; var FWH = ' width="728" height="90" '; var url = escape("%c%u"); var fscUrl = url; var fscUrlClickTagFound = false; var wmode = "opaque"; var bg = ""; var dcallowscriptaccess = "never"; var openWindow = "false"; var winW = 0; var winH = 0; var winL = 0; var winT = 0; var moviePath=swf.substring(0,swf.lastIndexOf("/")); var sm=new Array();
  13. 13. Tracking Example Setting up Flash Variables 1/2 var fv='"moviePath='+moviePath+'/'+'&moviepath='+moviePath+'/'; //This bit is essentially ignored: for(i=1;i<sm.length;i++){ if(sm[i]!=""){ fv+="&submovie"+i+"="+escape(sm[i]); } }
  14. 14. var defaultCtVal = escape("%c%u"); var ctp=new Array(); var ctv=new Array(); ctp[0] = "clickTag"; ctv[0] = ""; Setting up Flash Variables 2/2 for(var ctIndex = 0; ctIndex < ctp.length; ctIndex++) { var ctParam = ctp[ctIndex]; var ctVal = ctv[ctIndex]; if(ctVal != null && typeof(ctVal) == 'string') { if(ctVal == "") { ctVal = defaultCtVal; } else { ctVal = escape("%c" + ctVal); } if(ctParam.toLowerCase() == "clicktag") { fscUrl = ctVal; fscUrlClickTagFound = true; } else if(!fscUrlClickTagFound) { fscUrl = ctVal; } fv += "&" + ctParam + "=" + ctVal; } }
  15. 15. FV now has the value: "moviePath=%h/1436076/&moviepath=%h/1436076/&clickTag=%25c%25u"
  16. 16. function FSWin(){ if((openWindow=="false")&&(id=="DCF0"))alert('openWindow is wrong.'); var dcw = 800; var dch = 600; // IE if(!window.innerWidth) { // strict mode if(!(document.documentElement.clientWidth == 0)) { dcw = document.documentElement.clientWidth; dch = document.documentElement.clientHeight; } else if(document.body) // quirks mode { dcw = document.body.clientWidth; dch = document.body.clientHeight; } } else // w3c { dcw = window.innerWidth; dch = window.innerHeight; } if(openWindow=="center"){ winL=Math.floor((dcw-winW)/2);winT=Math.floor((dch-winH)/2); } window.open(unescape(fscUrl),id,"width="+winW+",height="+winH+",top="+winT+",le ft="+winL+",status=no,toolbar=no,menubar=no,location=no"); }
  17. 17. ua=navigator.userAgent; if( minV <= pVM && (openWindow =="false" || (ua.indexOf("Mac") < 0 && ua.indexOf("Opera") < 0 ) ) ){ var adcode='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="'+id+'"'+FWH+'>'+ '<param name="movie" value="'+swf+'"> <param name="flashvars" value='+fv+'> <param name="quality" value="high"> <param name="wmode" value="'+wmode+'">'+ '<param name="base" value="'+swf.substring(0,swf.lastIndexOf("/"))+'"> <PARAM NAME="AllowScriptAccess" VALUE="'+dcallowscriptaccess+'">'+bgo+ '<embed src="'+swf+'" flashvars='+fv+bge+FWH+' type="application/x-shockwave-flash" quality="high" swliveconnect="true" wmode="'+wmode+'" name="'+id+'" base="'+ swf.substring(0,swf.lastIndexOf("/"))+'" AllowScriptAccess="'+dcallowscriptaccess+'"></embed></object>'; if(('%eenv!'!="j")&&(typeof dclkFlashWrite!="undefined")){ dclkFlashWrite(adcode); }else{ document.write(adcode); } }
  18. 18. Tracking Example NoScript <noscript> <a target="_blank" href="%c%u"> <img src="%h/1436076/LW_gifting_728x90.gif" width="728" height="90" border="0" alt="" galleryimg="no"> </a> </noscript>
  19. 19. Spot the Problems! //Call the function myFunction(); var myfunction = function myFunction(){ if iWantToDoThis { doSomethingCrazyExciting( 'iAmAParameter ) doAnotherCrazyExcitingThing() }else{ iDontGetCalled(); } Hint: there are 6
  20. 20. Resources -Firefox + Firebug -W3C http://www.w3schools.com/jsref/ -http://jsfiddle.net/

×