Re: Click on a URL in WebKit
Re: Click on a URL in WebKit
- Subject: Re: Click on a URL in WebKit
- From: Rush Manbert <email@hidden>
- Date: Thu, 01 Jun 2006 09:54:27 -0700
Hi Malcom,
Replies inline.
malcom wrote:
loadArticle method need to take the URL string and
1- take the article data from a file inside the hard disk
2- make an html page on it
3- call articledata_webview loadHTMLString method to load the data
about the article
This sounds reasonable. The code you posted looks reasonable. As I
remember it, you need to be careful about what you use for baseURL if
your page contains links, but if you're just trying to load something
simple you should be okay.
You should fully implement the resource load delegates, because they
tell you a lot about what's happening (or not). See this for a good example:
http://developer.apple.com/documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/ResourceLoading.html
But when you click one of these nodes
(http://www.malcom-mac.com/files/webkit_test/prova.html) nothing will
happend and this method will never called. Instead it will be called
at the first time aftter awakeFromNib. Why?
In fact the code itself is pretty simple.
I've pasted it here:
http://pastebin.com/751330
Note that when I click on the link the page loads in Safari, so I don't
see the same behavior you do.
I am assuming that "this method" refers to loadArticle. If I'm wrong
about that, some things below may not make sense.
If your method never gets called, then consider the following questions.
The answers look obvious from the code that you posted, but sometimes
answering stupid questions can help:
1) Did you register your delegates?
i.e.
[webView setPolicyDelegate:self];
[webView setResourceLoadDelegate:self];
[webView setUIDelegate:self];
[webView setFrameLoadDelegate:self];
You don't need to register all of these, but unless you send
setPolicyDelegate, your decidePolicyForNavigationAction will never be
called.
2) Have you checked with gdb whether the load policy delegate method
ever gets called? It certainly should when your initial page is loaded.
3) If your policy delegate gets called, but you never call loadArticle,
then what is being returned by the "scheme" message? You need to enable
the NSLog call.
My only guess as to why your "loadArticle" method may be called at
awakeFromNib time is that you instantiated the web view and told it to
load your initial page. It got to the policy delegate method and the
test against "http" failed unexpectedly. I'd plant a breakpoint there
and see what the stack looks like. (The NSLog would help too.)
I really don't know how to intercept these links and make other things
rather than load a standard html page.thanks
You're on the right track, and it's fairly complicated. My app renders
pages using libxml and loads the resulting html string and also swaps
out pages on the fly in the willSendRequest delegate method. I'm telling
you this because if I can do it, you can do it. I have tons of NSLog
messages in the code because it's very hard to follow and debug. (As I
mentioned before, it recurses when you redirect the page load or stop
the current load and load a html string instead. It can get very
confusing in gdb.)
One thing I did early on was to write a little test app that used the
WebKit. This app would always just load a page. Then I wrote different
versions of the policy delegate. One just sent listener ignore, then
loaded a hard coded html string. Another loaded a different page from
disk. Stuff like that. It makes the flow a lot easier to understand,
particularly if you implement the resource load delegates and return
unique ID numbers for each resource that gets loaded. I played with the
test app for quite a while before I started putting together the real
thing and there were still a lot of little things to understand and work
out before it was reliable.
- Rush
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden