Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Getting Current URL Of WebView

Getting Current URL Of WebView
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Feb 15, 2004, 01:35 PM
 
Hi guys,

Something went wrong with the post, but anyway, what I want to do is get the current url of a webview and put that in a text field, I've looked through the WebView docs and cant see a way to get the url. Although there probably is:

Thanks,
Oliver
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 15, 2004, 07:43 PM
 
I haven't used the WebKit much, but from the documentation it looks like you could do something along the lines of [[[webView backForwardList] currentItem] URLString].
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Senior User
Join Date: Apr 2001
Location: Bolingbrook, IL, USA
Status: Offline
Reply With Quote
Feb 16, 2004, 12:19 AM
 
I use
Code:
[[[[webView_main mainFrame] dataSource] request] URL]
That should work. Though it a bunch more calls than the guy above me's idea.
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Feb 16, 2004, 04:04 AM
 
Hi guys,

I took Chuckits code and made it like:

Code:
NSString *currentURL = [[[helpWebView backForwardList] currentItem] URLString]; [helpURLBar setStringValue:(currentURL == nil ? @"" : currentURL)];
helpURLBar is the NSTextField. I load up my window that has the WebView in, it has nothing loaded. I click a button and it loads a website, but the text field still displays nothing, any ideas?

Thanks,
Oliver
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Feb 16, 2004, 04:54 AM
 
I'd go with Overmind's solution, personally. That seems more like how it's intended to be done. I just went for the more obvious method named "backForwardList."
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
Feb 16, 2004, 06:08 AM
 
Im a little confused by this, I tried Overminds code which is:

Code:
NSString *currentURL = [[[[helpWebView mainFrame] dataSource] request] URL]; [helpURLBar setStringValue:(currentURL == nil ? @"" : currentURL)];
I get this warning "initialization from incompatible pointer type". Here is a screeny of what Im trying to do:



Notice how the url bar is empty? What I want is the url of the page in the WebView in the TextField above it. The TextField is not editable, and I've tried it where its just normal, still doesn't work.

Any ideas?
Thanks,
Oliver
     
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status: Offline
Reply With Quote
Feb 16, 2004, 11:54 AM
 
you probably want to get the -absoluteString from the NSURL
     
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Feb 17, 2004, 07:30 AM
 
Yeah. currentURL is an NSString, and [[[[helpWebView mainFrame] dataSource] request] URL] returns an NSURL (or so I'm assuming; I haven't worked with WebKit myself yet).
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:59 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2