Re: WebKit - javascript / DOM listeners only fire once
Re: WebKit - javascript / DOM listeners only fire once
- Subject: Re: WebKit - javascript / DOM listeners only fire once
- From: "Stephen J. Butler" <email@hidden>
- Date: Sun, 13 Feb 2011 14:50:59 -0600
On Sun, Feb 13, 2011 at 8:02 AM, Darren Wheatley
<email@hidden> wrote:
> When the application runs and the user clicks on the first row, everything works fine. The "click" event is trapped, and my Objective-C method is successfully called.
>
> However, when the user clicks on a second (or subsequent) record and then a new HTML page is loaded in to the same WebView the listener on "click" never fires.
>From the documentation for -webView:didClearWindowObject:forFrame:
"Use this method to set custom properties on the window object before
the page is actually loaded. Every time a frame loads or is reloaded
all DOM properties are cleared from the window object so the new page
has a fresh window object to use. If the page you are loading depends
on specific window object properties to exist, they should be added at
this point before any scripts are executed."
You need to move where you set your AppDelegate from
applicationDidFinishLaunching into this
-webView:didClearWindowObject:forFrame:. For example:
- (void) webView:(WebView *)sender
didClearWindowObject:(WebScriptObject *)windowObject
forFrame:(WebFrame *)frame
{
[windowObject setValue:self forKey:@"AppDelegate"]; // can be any
unique name you want
}
Also, I wouldn't use "retain" on any properties set via IBOutlet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden