1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

WebKit - load pages without http:

Discussion in 'Mac Programming' started by slooksterPSV, Feb 23, 2007.

  1. macrumors 68030

    slooksterPSV

    #1
    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 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
     
  2. Moderator

    robbieduncan

    Staff Member

    #2
    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.
     
  3. macrumors 6502

    #3
    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...?
     
  4. macrumors 68030

    slooksterPSV

    #4
    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]];
    }
    
     
  5. Moderator

    robbieduncan

    Staff Member

    #5
    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.
     
  6. macrumors 68030

    slooksterPSV

    #6
    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.
     
  7. macrumors 68030

    slooksterPSV

    #7
    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.
     

Share This Page