Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
I'm trying to make a web browser, and I'm stuck, how can I make it so that even if the user jjust types in http://www.msn.com it takes them to http://www.msn.com/ I can't get it to work, here's my code for connectURL: as apple has it on their site:
Code:
- (IBAction)connectURL:(id)sender{
    [[webView mainFrame] loadRequest:
	[NSURLRequest requestWithURL:
	[NSURL URLWithString:
	[sender stringValue]]]];
}
Help would be greatly appreciated
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
You need a protocol to connect (i.e. http://). WebKit is not going to do this for you: you are the programmer fix it. It's pretty simple to check if the address starts with a recognised protocol and if not add http:// so the start of the string.
 

bmb012

macrumors 6502
Jul 25, 2006
414
0
Erm, if it's a string, can't you just look for http in the beginning of the string, and if it's not there, do some "http://" + string or whatever...?
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Ok I just reused the code from the other version I have, but now I have another problem, when I try to set its background color, it doesn't work, it still stays the line through type texture. It doesn't change it to the color I want like the other one does, its in the awakeFromNib and the function executes correctly, and its linked in MyDocument.nib so what's wrong with it now here's the code
Code:
- (void)awakeFromNib
{
	[window setBackgroundColor:[NSColor colorWithDeviceRed: 0.837 green: 0.837 blue:0.837 alpha:1.0]];
}
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Are you sure that the window background is not being correctly set? If you have a view that covers the window entirely then setting the window background will have no effect as the view will draw over it.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
Yup the WebView is pretty big but it doesn't cover the window, the window is connected to the File's Owner window variable and awakeFromNib is being called. In regular apps that aren't document-based it works, but this one doesn't.
 

slooksterPSV

macrumors 68040
Original poster
Apr 17, 2004
3,544
306
Nowheresville
It won't even tell me the title of the window, so the window is connected, but its not telling me any information about it.

EDIT: Fixed it, I had to add a new NSObject that linked to the Window, since the window was based in the MyDocument class, it couldn't exactly modify the window, so yeah.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.