• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2
3 <head><title>Click noreferrer links</title>
4 <script>
5  function simulateClick(target) {
6    var evt = document.createEvent("MouseEvents");
7    evt.initMouseEvent("click", true, true, window,
8                       0, 0, 0, 0, 0, false, false,
9                       false, false, 0, null);
10
11    return target.dispatchEvent(evt);
12  }
13
14  function clickNoRefTargetBlankLink() {
15    return simulateClick(document.getElementById("noref_and_tblank_link"));
16  }
17
18  function clickSameSiteNoRefTargetedLink() {
19    return simulateClick(
20        document.getElementById("samesite_noref_and_targeted_link"));
21  }
22
23  function clickSameSiteTargetedLink() {
24    return simulateClick(document.getElementById("samesite_targeted_link"));
25  }
26
27  function clickSameSiteTargetBlankLink() {
28    return simulateClick(document.getElementById("samesite_tblank_link"));
29  }
30
31  function clickTargetBlankLink() {
32    return simulateClick(document.getElementById("tblank_link"));
33  }
34
35  function clickNoRefLink() {
36    return simulateClick(document.getElementById("noref_link"));
37  }
38
39  function testScriptAccessToWindow() {
40    // Grab a reference to the existing foo window and access its location.
41    try {
42      var w = window.open("", "foo");
43      var url = w.location.href;
44      return url != undefined;
45    } catch (e) {
46      return false;
47    }
48  }
49
50  function testCloseWindow() {
51    // Grab a reference to the existing foo window and close it.
52    var w = window.open("", "foo");
53    w.close();
54    return true;
55  }
56
57  // Listen to incoming messages and reply to them.
58  var receivedMessages = 0;
59  window.addEventListener("message", messageReceived, false);
60  function messageReceived(event) {
61    receivedMessages++;
62    event.source.postMessage(event.data, "*");
63  }
64
65  // Send a message which contains a message port.
66  var mc;
67  function postWithPortToFoo() {
68    mc = new MessageChannel();
69    mc.port1.onmessage = portMessageReceived;
70    mc.port1.start();
71    var w = window.open("", "foo");
72    w.postMessage({message: "msg-with-port", port: mc.port2}, "*", [mc.port2]);
73    return true;
74  }
75
76  var receivedMessagesViaPort = 0;
77  function portMessageReceived(event) {
78    receivedMessagesViaPort++;
79    // Change the title to generate a notification.
80    document.title = event.data;
81  }
82 </script>
83 </head>
84
85<a href="https://REPLACE_WITH_HOST_AND_PORT/files/title2.html"
86   id="noref_and_tblank_link" rel="noreferrer" target="_blank">
87  rel=noreferrer and target=_blank</a><br>
88<a href="title2.html" id="samesite_noref_and_targeted_link"
89   rel="noreferrer" target="foo">
90  same-site rel=noreferrer and target=foo</a><br>
91<a href="navigate_opener.html" id="samesite_targeted_link" target="foo">
92  same-site target=foo</a><br>
93<a href="title2.html" id="samesite_tblank_link" target="_blank">
94  same-site target=_blank</a><br>
95<a href="https://REPLACE_WITH_HOST_AND_PORT/files/title2.html" id="tblank_link"
96   target="_blank">target=_blank</a><br>
97<a href="https://REPLACE_WITH_HOST_AND_PORT/files/title2.html" id="noref_link"
98   rel="noreferrer">rel=noreferrer</a><br>
99
100<iframe id="frame1" src="frame_tree/1-1.html"></iframe>
101
102</html>
103