View Full Version : Google Search Bar in Browser
Programmer
Jun 16, 2009, 09:01 PM
could someone please help me figure out how to put a google search bar in the web browser I'm making in xcode.:eek:
Nukemkb
Jun 16, 2009, 09:04 PM
hmm. select View, then 'customize toolbar', then drag it and drop it....
veterator
Jun 16, 2009, 09:05 PM
You are using Safari, right?
Nukemkb
Jun 16, 2009, 09:06 PM
You are using Safari, right?
Good question!
Programmer
Jun 18, 2009, 04:10 PM
no i'm i am trying to program it into my web browser i'm making in xcode.
Thomas Harte
Jun 18, 2009, 07:00 PM
no i'm i am trying to program it into my web browser i'm making in xcode.
How do you currently have your webView set up to get page URLs? Do you have it connected to an NSTextField via takeStringURLFrom: or are you pushing URLs to it with setMainFrameURL:?
In either case, you'll want to set yourself up as a delegate of a second NSTextField, do something like this when you receive textDidEndEditing: from it:
NSString *searchURL = [NSString stringWithFormat:@"http://www.google.com/search?q=%@", [googleField stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
Then set searchURL to your normal URL bar, possibly passing it to the WebView as well if you have the link between the two going through your own code.
The main observations are merely that you need to:
(i) escape the search string (eg, to turn a space into %20 so that it works in a URL); and
(ii) add http://www.google.com/search?q= to the start to turn it into a Google search URL.
Then just treat that identically to a URL directly entered by the user.
Programmer
Jun 18, 2009, 07:41 PM
thanks
what i'v been having trouble with is when i try to retrieve the text from the google search bar in the .h file then do the @synthesize in the .m file to put it into this string of code
NSString *searchURL = [NSString stringWithFormat:@"http://www.google.com/search?q=%@", [GoogleSearchField stringValue]];
i am used to programing on the iphone this is what i would normally do so i don't know if it is different on a mac
Programmer
Jul 9, 2009, 10:01 PM
i'm making a web browser but when i run this code
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"];
[textField resignFirstResponder];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];
return YES;
}
i get this
Expected expression before NSString
can anyone help
dejo
Jul 9, 2009, 10:43 PM
First (and we really need to sticky this for this forum), if you're going to include cope snippets, please enclose them in [ CODE ][ /CODE ] tags (spaces removed). These tags are easily accessed via the # icon in the toolbar.
Second, your problem starts here:
- (BOOL)textFieldShouldReturnUITextField *)textField
You probably want something like this instead:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
...and continues here:
NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"];
You probably want something like this:
NSString *searchURL = [NSString stringWithFormat:@"http://%@%@", [textField text], @".com"];
autorelease
Jul 10, 2009, 12:19 PM
NSString *searchURL = [NSString stringWithFormat:@"http://", [urlField stringValue], NSString stringWithFormat:@".com"]
Learn about strings. That line is nonsense.
What you want is
NSString *searchURL = [NSString stringWithFormat:@"http://%@.com", [urlField stringValue]]
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.