<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>Evil XML: Script Access to Secondary XML Windows</title>
  <script type="text/javascript">
  <![CDATA[
   var friend;
   function test() {
     log('opening test document');
     friend = window.open('001b.xml', 'SecondaryWindow');
     log('test document opened');
     window.setTimeout(poke, 2000);
   }
   function poke() {
     log('poke() started');
     friend.document.documentElement.appendChild(friend.document.createTextNode('Hello World!'));
     friend.document.insertBefore(friend.document.createProcessingInstruction('xml-stylesheet', 'href="001b.css"'), friend.document.documentElement);
     log('poke() ended');
   }
   function bg() {
     if (friend.document.documentElement.attributes.getNamedItem('bg')) {
       log('removing bg attribute');
       friend.document.documentElement.attributes.removeNamedItem('bg');
     } else {
       log('adding bg attribute');
       friend.document.documentElement.setAttribute('bg', 'set');
     }
     log('done');
   }
   function addtext() {
     log('adding text');
     friend.document.documentElement.appendChild(friend.document.createTextNode(' Added more text!'));
     log('done');
   }
   function log(s) {
     document.getElementById('log').appendChild(document.createTextNode(s + "\n"));
   }
  ]]>
  </script>
 </head>
 <body onload="test()">
  <p>A second window should have popped up. The initial contents of
  the window is the seven-character XML file "&lt;text/&gt;". It is
  dynamically populated with an XML stylesheet PI and some text two
  seconds after being opened. The following buttons allow you to
  dynamically toggle attributes and add new text nodes. </p>
  <p>
   <input type="button" value="Change Background" onclick="bg()"/>
   <input type="button" value="Add Text" onclick="addtext()"/>
  </p>
  <p>If the window didn't pop up or to restart the test:
   <input type="button" value="Force popup" onclick="test()"/>
  </p>
  <pre id="log"></pre>
 </body>
</html>
