开发者

Message when a WebView's window is closed?

In my program I have an 开发者_JAVA技巧NSPanel containing a web view appear to a user to have them authenticate on a web page. I want to monitor if the user is closing the WebView before the authentication is complete.

I looked for messages in the WebFrameLoadDelegate protocol but I couldn't seem to find any message that would fire when the user clicks the close button for the NSPanel and only when the user clicks the close button.

I looked at subclassing NSWindowController and overriding the close method. Perhaps I did it wrong, because even when I removed the [super close] call, the panel still closed.

So, what is the correct procedure for executing extra code when the NSPanel containing the WebView closes?


If you want to stop the user from closing a window, you need to set the window's style mask to one that doesn't include NSCloseableWindowMask. This will disable the window's close button, so that it can only be closed programmatically. In the simplest case, you can just do [panel setStyleMask:[panel styleMask] ^ NSCloseableWindowMask].

Also, if you want to override a window's closing behavior, you either need to override NSWindow's (not NSWindowController's) close method, or implement windowShouldClose: on the window's delegate. I think the second way is better. At any rate, -[NSWindowController close] is just a convenience method to close the window. It isn't what's normally invoked when a window closes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜