Webview doesn't update page

I’ve searched and I didn’t see an answer to my problem (I suspect I saw my problem, but it wasn’t well defined or answered).

I have a webview in a panel. It successfully loads a page in awake from nib, but after that it gets funky. It doesn’t update the web page contents until I grab and drag a draggable element (a link or graphic). It doesn’t matter if I navigate to a link in the webview or change the connected text field. The sample code minibrowser works, albeit slowly, so I suspect it’s not the framework. I’m confused. Maybe it doesn’t like my panel as a parent?

I’d like to update the URLText field when someone clicks inside the page (and other things, but crawling first, then walking).

The system is 10.4.9. My code (found here!, thank you!) is as follows:


on clicked theObject --> the buttons, for use later...
	if name of theObject is "CancelButton" then
		close panel window "WebPanel" with result -1
	else if name of theObject is "WebUploadButton" then
		close panel window "WebPanel" with result 1
	end if
	
end clicked

on end editing theObject --> attached to text field "URLText"

	set MyPage to contents of text field "URLText" of window "WebPanel"
	LoadWebPage(MyPage)
	tell window "WebPanel" to set first responder to view "Webview"
	
end end editing

on LoadWebPage(PageURL)

	try
		set contents of text field "URLText" of window "WebPanel" to PageURL
		
		set webView to view "webView" of window "WebPanel"
		--call method "setEditable:" of (webView) with parameters {true}
		set URLWithString to call method "URLWithString:" of class "NSURL" with parameter PageURL
		set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
		
		set mainframe to call method "mainFrame" of object webView
		call method "loadRequest:" of mainframe with parameter requestWithURL
	on error theError
		display dialog "Couldn't load web page:" & theError
	end try
end LoadWebPage


on opened theObject --> Attached to the window
	set LastURL to "http://www.whiterose.org/michael/"
	--display dialog LastURL
	set contents of text field "URLText" of window "WebPanel" to LastURL
	tell window "WebPanel" to set first responder to view "Webview"
	LoadWebPage(LastURL)
	
	
end opened

on awake from nib theObject

	set LastURL to "http://www.whiterose.org/"
	--display dialog LastURL
	set contents of text field "URLText" of window "WebPanel" to LastURL
	tell window "WebPanel" to set first responder to view "Webview"
	LoadWebPage(LastURL)
end awake from nib



Have you tried setting breakpoints in the debugger to see what might be happening? On first glance, I see you setting the contents of URLtext at the beginning of the load sequence and wonder if it’s not triggering another end editing handler.

your script looks fine and is working in a panel (tried it) - might it be that you omitted ‘http://’ in the web adress(es) you tried?

Thanks for replying.

OK, now I’m confused. It works if I am stepping through the code. So, I assumed this meant a race condition, but I put in display dialog statements between every call to tell me where I am and it still didn’t refresh properly. While stepping, it still doesn’t load pages when clicking links (just on end editing)

Kevin: end editing is only called once, but I took out that call to test things.
Dominick: no, it’s there. I see the page at the URL from the awake from nib event, but not the opened event, where it’s hardcoded in the method.

tested it on my dev machine (G5) and a handy intel mini, so it’s not just my box…

Model: G5 2x2.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

sry - I didn’t notice the opened handler :wink: … but what do you expect it to do? It in fact works but is overruled by the next LoadWebPage(LastURL) call in awakeFromNib - so you won’t see it. Add a ‘delay 5’ at the end of the opened hander and you will see the /michael page …

Sounds like I really don’t understand when awake from nib fires. I will remove the LoadFromURL call from awake from nib and see if that solves it.

So, removing it from Awake from nib ended up with nothing being updated.

I created a new webview in the mainmenu.nib and then it started updating. I don’t understand the difference, but I see the results.

I’m also having problems getting updates after I resize that window, but I need to nail down when that happens.