HTML java c#
appla · 2008-03-12(近似)
2008年01月18日
The javascript: protocol
- [
]
Tag:
A URI using the
javascript:
protocol must, if evaluated, be evaluated using the in-context evaluation operation defined for
javascript:
URIs.
[JSURI]
When a browsing context is
navigated
to a
javascript:
URI, and the
active document
of that browsing context has the same
origin
as the URI, the dereference context must be the
browsing context
being navigated.
When a browsing context is
navigated
to a
javascript:
URI, and the
active document
of that browsing context has a
different
origin
than the URI, the dereference context must be an empty object.
Otherwise, the dereference context must the
browsing context
of the
Document
to which belongs the element for which the URI is being dereferenced, or to which the style sheet for which the URI is being dereferenced applies, whichever is appropriate.
URIs using the
javascript:
protocol should be evaluated when the resource for that URI is needed, unless
scripting is disabled
or the
Document
corresponding to the dereference context (as defined above), if any, has
designMode
enabled.
If the dereference by-product is void (there is no return value), then the URI must be treated in a manner equivalent to an HTTP resource with an HTTP 204 No Content response.
Otherwise, the URI must be treated in a manner equivalent to an HTTP resource with a 200 OK response whose
Content-Type metadata
is
text/html
and whose response body is the dereference by-product, converted to a string value.
Certain contexts, in particular
img
elements, ignore the
Content-Type metadata
.
So for example a
javascript:
URI for a
src
attribute of an
img
element would be evaluated in the context of the page as soon as the attribute is set; it would then be sniffed to determine the image type and decoded as an image.
A
javascript:
URI in an
href
attribute of an
a
element would only be evaluated when the link was
followed
.
The
src
attribute of an
iframe
element would be evaluated in the context of the
iframe
's own
browsing context
; once evaluated, its return value (if it was not void) would replace that
browsing context
's document, thus changing the variables visible in that
browsing context
.
4.3.6.
Events
We need to define how to handle events that are to be fired on a Document that is no longer the active document of its browsing context, and for Documents that have no browsing context. Do the events fire? Do the handlers in that document not fire? Do we just define scripting to be disabled when the document isn't active, with events still running as is? See also the
script
element section, which says scripts don't run when the document isn't active.
4.3.6.1.
Event handler attributes
HTML elements
can have event handler attributes specified. These act as bubbling event listeners for the element on which they are specified.
Each event handler attribute has two parts, an
event handler content attribute
and an
event handler DOM attribute
. Event handler attributes must initially be set to null. When their value changes (through the changing of their event handler content attribute or their event handler DOM attribute), they will either be null, or have an
EventListener
object assigned to them.
Objects other than
Element
objects, in particular
Window
, only have
event handler DOM attribute
(since they have no content attributes).
Event handler content attributes, when specified, must contain valid ECMAScript code matching the ECMAScript
FunctionBody
production.
[ECMA262]
When an event handler content attribute is set, its new value must be interpreted as the body of an anonymous function with a single argument called
event
, with the new function's scope chain being linked from the activation object of the handler, to the element, to the element's
form
element if it is a form control, to the
Document
object, to the
browsing context
of that
Document
. The function's
this
parameter must be the
Element
object representing the element. The resulting function must then be set as the value of the corresponding event handler attribute, and the new value must be set as the value of the content attribute. If the given function body fails to compile, then the corresponding event handler attribute must be set to null instead (the content attribute must still be updated to the new value, though).
See ECMA262 Edition 3, sections 10.1.6 and 10.2.3, for more details on activation objects.
[ECMA262]
How do we allow non-JS event handlers?
Event handler DOM attributes, on setting, must set the corresponding event handler attribute to their new value, and on getting, must return whatever the current value of the corresponding event handler attribute is (possibly null).
The following are the event handler attributes that must be supported by all
HTML elements
, as both content attributes and DOM attributes, and on
Window
objects, as DOM attributes:
onabort
Must be invoked whenever an
abort
event is targeted at or bubbles through the element.
onbeforeunload
Must be invoked whenever a
beforeunload
event is targeted at or bubbles through the element.
onblur
Must be invoked whenever a
blur
event is targeted at or bubbles through the element.
onchange
Must be invoked whenever a
change
event is targeted at or bubbles through the element.
onclick
Must be invoked whenever a
click
event is targeted at or bubbles through the element.
oncontextmenu
Must be invoked whenever a
contextmenu
event is targeted at or bubbles through the element.
ondblclick
Must be invoked whenever a
dblclick
event is targeted at or bubbles through the element.
ondrag
Must be invoked whenever a
drag
event is targeted at or bubbles through the element.
ondragend
Must be invoked whenever a
dragend
event is targeted at or bubbles through the element.
ondragenter
Must be invoked whenever a
dragenter
event is targeted at or bubbles through the element.
ondragleave
Must be invoked whenever a
dragleave
event is targeted at or bubbles through the element.
ondragover
Must be invoked whenever a
dragover
event is targeted at or bubbles through the element.
ondragstart
Must be invoked whenever a
dragstart
event is targeted at or bubbles through the element.
ondrop
Must be invoked whenever a
drop
event is targeted at or bubbles through the element.
onerror
Must be invoked whenever an
error
event is targeted at or bubbles through the element.
The
onerror
handler is also used for
reporting script errors
.
onfocus
Must be invoked whenever a
focus
event is targeted at or bubbles through the element.
onkeydown
Must be invoked whenever a
keydown
event is targeted at or bubbles through the element.
onkeypress
Must be invoked whenever a
keypress
event is targeted at or bubbles through the element.
onkeyup
Must be invoked whenever a
keyup
event is targeted at or bubbles through the element.
onload
Must be invoked whenever a
load
event is targeted at or bubbles through the element.
onmessage
Must be invoked whenever a
message
event is targeted at or bubbles through the element.
onmousedown
Must be invoked whenever a
mousedown
event is targeted at or bubbles through the element.
onmousemove
Must be invoked whenever a
mousemove
event is targeted at or bubbles through the element.
onmouseout
Must be invoked whenever a
mouseout
event is targeted at or bubbles through the element.
onmouseover
Must be invoked whenever a
mouseover
event is targeted at or bubbles through the element.
onmouseup
Must be invoked whenever a
mouseup
event is targeted at or bubbles through the element.
onmousewheel
Must be invoked whenever a
mousewheel
event is targeted at or bubbles through the element.
onresize
Must be invoked whenever a
resize
event is targeted at or bubbles through the element.
onscroll
Must be invoked whenever a
scroll
event is targeted at or bubbles through the element.
onselect
Must be invoked whenever a
select
event is targeted at or bubbles through the element.
onsubmit
Must be invoked whenever a
submit
event is targeted at or bubbles through the element.
onunload
Must be invoked whenever an
unload
event is targeted at or bubbles through the element.
When an event handler attribute is invoked, its argument must be set to the
Event
object of the event in question. If the function returns the exact boolean value false, the event's
preventDefault()
method must then invoked. Exception: for historical reasons, for the HTML
mouseover
event, the
preventDefault()
method must be called when the function returns true instead.
When
scripting is disabled
, event handler attributes must do nothing.
When
scripting is enabled
, all event handler attributes on an element, whether set to null or to a function, must be registered as event listeners on the element, as if the
addEventListenerNS()
method on the
Element
object's
EventTarget
interface had been invoked when the element was created, with the event type (
type
argument) equal to the type described for the event handler attribute in the list above, the namespace (
namespaceURI
argument) set to null, the listener set to be a target and bubbling phase listener (
useCapture
argument set to false), the event group set to the default group (
evtGroup
argument set to null), and the event listener itself (
listener
argument) set to do nothing while the event handler attribute is null, and set to invoke the function associated with the event handler attribute otherwise.
luguangjun
发表于22:09:21 |
引用(0)
|
编辑
原始快照:web.archive.org