SI110 Spring AY13 choose one: (or more) Homework: Alpha:___________ □ Received no help Name:________________________________ Page 1 of 2 □ Received help from: □ Collaborated with:________________________________________ /SI110/The Cyber Battlefield/ HTML Client Side Scripting: Non-event driven 1. Draw what would appear in a browser if the following html files were loaded: a. b. <html> <body> <u>You</u> <script type="text/javascript"> document.write("don’t"); </script> <p>rock</p> </body> </html> 10 / 8 / 6 / 0 <html> <body> <u>You</u> document.write("don’t"); <p>rock</p> </body> </html> 10 / 8 / 6 / 0 2. The page http://rona.cs.usna.edu/~si110/lec/l11/hw/hw1.html contains a secret message. What is it, and how did you figure it out? 10 / 0 / 0 / 0 Unhelpful Hint: If you know the trick, this takes two seconds. 3. Suppose you are creating a great new website. You find out that there’s a nice piece of free-to-use javascript at http://free2usescripts.com/dancinbear.js that produces a cool animated dancing bear, and you decide you want to add it to your webpage. You have two ways to do this: 30 / 25 / 20 / 15 / 10 / 5 / 0 : 5 per cell Option a. Put in your page: <script type="text/Javascript" src="http://free2usescripts.com/dancinbear.js"></script> Option b. Save a copy of the script locally as dancingbearcopy.js & put in your page: <script type="text/Javascript" src="dancinbearcopy.js"></script> You recognize that using code from other folks carries some risk, after all what if this code included document.location=’http://www.lotsaevil.org’? That’d ruin your site! In this light, maybe one of the two options is safer than the other. In the table below, cross out any entries that you are not secure against. With Option a you are secure against … With Option b you are secure against … Past & current evil from the folks at free2usescripts.com Past & current evil from the folks at free2usescripts.com Future evil from the folks at free2usescripts.com Future evil from the folks at free2usescripts.com Future attacks against folks at free2usescripts.com Future attacks against folks at free2usescripts.com SI110 Spring AY13 Alpha:___________ Name:________________________________ Page 2 of 2 4. View the following two pages, whose HTML source is shown below: http://rona.cs.usna.edu/~si110/lec/l11/hw/hw3.html <html> <head></head> <body> <script type="text/javascript"> alert("Get ready for a surprise!"); </script> ... and the surprise is ... <script type="text/javascript"> document.location = "http://www.usma.edu"; </script> </body> </html> http://rona.cs.usna.edu/~si110/lec/l11/hw/hw4.html <html> <head></head> <body> <script type="text/javascript"> document.location = "http://www.usma.edu"; </script> ... and the surprise is ... <script type="text/javascript"> alert("Get ready for a surprise!"); </script> </body> </html> 15 / 12 / 8 / 0 a. Describe the difference in what happens when you visit hw3.html versus hw4.html, and explain why that different behavior happens in terms of the HTML source code shown above. b. Turn off Javascript in your browser (just for this problem!) and go view the two pages again. Describe what you see on the two pages now, and explain the change. (Note: you might have to enter the two URL’s by 15 / 12 / 8 / 0 hand, i.e. by copy&paste or typing, now that you’ve turned off Javascript!) 5. Goto http://rona.cs.usna.edu/~si110/lec/l11/hw/hello.html and hit refresh a bunch of times. A copy of the HTML source code appears below. Fill in a,b,c below with short descriptions of what the chunk of code immediately below it accomplishes. I.e. what it does, not how it does it. 10 / 8 / 6 / 0 <html> <body> <script type="text/javascript"> var msg = "Hello World!"; var i = 0; while(i < msg.length) { // a._______________________________________________________ var r = Math.floor(16 + Math.random() * 239).toString(16); var g = Math.floor(16 + Math.random() * 239).toString(16); var b = Math.floor(16 + Math.random() * 239).toString(16); var s1 = "color: #" + r + g + b + ";"; // b._______________________________________________________ var fsize = Math.floor(24 + Math.random() * 32); var s2 = "font-size: " + fsize + "pt;"; // c._______________________________________________________ document.write("<span style='" + s1 + s2 + "'>" + msg[i] + "</span>"); i = i + 1; } </script> </body> </html> 6. Extra Credit (25 points): create a webpage at http://rona.cs.usna.edu/~m16xxxx/ec.html that is a copy of the above webpage with some additional feature that uses randomness, i.e. that changes with each refresh. Your instructor must be able to open it. Briefly explain below what the random feature you added! Page 2 of 2