I recently tuned NetSurf also encountered a related Bug:alert () was transferred two times. HTML code:
Copy Code code as follows:
<title>alert onclick example</title>
<script type= "Text/javascript" >
function Causealert ()
{
var txt = document.getElementById ("P1"). Textcontent;
alert (TXT);
}
</script>
<body>
<div style= "border:1px solid Red" >
<p id= "P1" >first line of Paragraph.<br/></p>
</div><br/>
<button id= "Button1" >add another textnode.</button>
<script>
var Button1 = document.getElementById ("button1");
/*var Button1Click = function () {alert (1);};
Button1.addeventlistener ("Click", Button1Click, false);
Button1.onclick = Causealert;
</script>
</body>
Via GDB, navigate to the problem within _dom_node_dispatch_event ():
Copy Code code as follows:
/* The capture phase * * for (TARGETNR = ntargets; targetnr > 0;--targetnr) ...
/* bubbling Phase * *
Evt->phase = Dom_bubbling_phase;
for (Targetnr = 0; Targetnr < ntargets; ++targetnr)
The event flow is this: P1 (root)-->p2--> ...--> pm--> t (capturing phase), T (target phase), t--> pm--> ...--> p 1 (bubbling phase).
The specification stipulates capturing and bubbling can only choose one, in the code in Js_dom_event_add_listener () is chooses the capturing. So it explains why alert was executed two back.
Modify: According to the DOM 3 specification, the above 0 is changed to 1 on the line.