Html程序  |  47行  |  1.36 KB

<html>

 <head><title>Click nocontent link</title>
 <script>
  function simulateClick(target) {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
                       0, 0, 0, 0, 0, false, false,
                       false, false, 0, null);

    return target.dispatchEvent(evt);
  }

  function clickNoContentTargetedLink() {
    return simulateClick(document.getElementById("nocontent_targeted_link"));
  }

  function clickNoContentScriptedTargetedLink() {
    return simulateClick(document.getElementById(
        "nocontent_scripted_targeted_link"));
  }

  var w;
  function modifyNewWindow() {
    // Grab a reference to the existing foo window and modify its content.
    w = window.open("", "foo");
    w.document.body.innerHTML += "Modified";

    // Also modify the title to give the test a notification to listen for.
    // Use a timeout so that the didAccessInitialDocument notification arrives
    // first.
    setTimeout('w.document.title = "Modified Title"');
    return true;
  }
 </script>
 </head>

<a href="/nocontent" id="nocontent_targeted_link" target="foo">
  /nocontent target=foo</a><br>
<button onclick="modifyNewWindow()">Modify New Window</button><br>

<a href="/nocontent" id="nocontent_scripted_targeted_link" target="foo"
   onclick="modifyNewWindow()">
  /nocontent scripted target=foo</a><br>

</html>