问题
I can't find any documentation on the "beforeload" event other than the Blocking Unwanted Content section of this.
What I'm specifically looking for is the event message structure. From the above doc I know that there is a "event.url" member, but not much else. From a snip of source code I know there's also a "event.target.nodeName" member. But I don't have anything more than that.
I got lost in both the WebKit docs and w3 event docs. Where can I find some simple reference documentation for the "beforeload" event?
回答1:
Event messages (SafariExtensionMessageEvent
instances) only have a name
and a message
(class documentation). It's actually discussed on the same page.
Interestingly, the event class (SafariEvent) documentation doesn't mention a url
property or method so either an object of a different class is being passed or something else is going on.
Like you, I've found Apple's documentation to be wanting, at best. To write the small extensions I've wanted to write, I've had to cobble together information from various locations within the docs. If you're wondering whether you're the only one that's had to work way too hard to complete relatively straightforward tasks...you're not. :-)
回答2:
The DOM beforeload event is a WebKit concept, it is not specific to Safari extensions. It does have a URL property.
For some more information about the beforeload event - you can see:
http://opensource.apple.com/source/WebCore/WebCore-1298/dom/BeforeLoadEvent.idl
If you are using this in an extension content script, one way to get some more information about be to have some code like:
document.addEventListener("beforeload", beforeLoadHandler, false);
function beforeLoadHandler(event)
{
console.log(event);
}
And then use the Web Inspector to view information about the event (you can see its URL, you can look at the event target, etc).
回答3:
The example should set the capture argument to 'true', not 'false' when used from page content. I'm not sure how that will affect its use in extensions, but people are using this from page content directly and using it to rewrite pages. And you need to capture in that case.
来源:https://stackoverflow.com/questions/4395525/safari-extension-beforeload-event-documentation