3

I've read over the beforeload documentation from Apple, but I'm still a bit uncertain about how beforeload cancels a load, from a network perspective. Apple's documentation says:

Safari 5.0 and later (and other WebKit-based browsers) generates a "beforeload" event before loading each subresource belonging to a webpage.

There's nothing in the sparse documentation here that suggests to me that a beforeload block must prevent a HTTP fetch of the resource. What does the operation of "loading" a Web resource entail (e.g., is there a formal definition of loading in some W3C spec)? In Webkit's current implementation, does canceling a load with beforeload stop the browser from sending a HTTP request, or does it merely stop the resource from being rendered and firing a load event?

I'm primarily instead in these question to assess beforeload's usefulness to block tracking images. I know there are other ways to do this (e.g., Chrome's webRequest API), but I want to know if beforeonload is also suitable.

4

1 回答 1

2

beforeload严格来说并不能阻止任何事情。它只是提供了机会preventDefault()

你的堆栈使用dispatchMessage()吗?这是异步的,允许在您阻止之前开始获取资源。

你读过 http://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/SafariExtensionGuide.pdf#page=88吗?它提供了一种同步方法(第 91-92 页)

ps
我会将此添加为评论而不是答案,但我还不能添加评论

于 2012-09-24T15:07:45.710 回答