Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8134595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:05:29+00:00 2026-06-06T10:05:29+00:00

I’m trying to do a UIWebView , but not allowing the user to visit

  • 0

I’m trying to do a UIWebView, but not allowing the user to visit other part of the given URL. Something like they could only go specific pages where i allow them to go, and not others.

I’m not too sure about the - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType method, so I may have made a mistake there. The problem now is that if I enable this method, I am loaded into the webpage but am unable to browse. Not even the section i allow.

I would like to know if 1)Am I missing out any important code?, 2)Am I missing anything in the code, or why is my code wrong?

Am new to Xcode, so I will require all the guidance that you guys can give/teach me. Below is my code from the view controller.

EDIT1: Is there any prebuilt method by Xcode, or do I have to create my own method, such that when they are browsing the UIWebView, and when they click on another link, if its something other than what I specify, the request get rejected? Is it possible to create a method such that it will constantly check the absolute url and if it change to something else other than what i specify, it will return to my specified url?

in my.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController<UIWebViewDelegate>

{
    IBOutlet UIWebView *webView;
}

@property (nonatomic, retain)  UIWebView *webView;  

@end

in my .m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize webView;

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *currentURL = [[request URL]absoluteString];
    NSRange range1 = [currentURL rangeOfString:@"news"];
    NSRange range2 = [currentURL rangeOfString:@"pdf"];



    if (range1.location ==NSNotFound){
        currentURL = @"http://www.imc.jhmi.edu/news.html";
        [webView reload];
        return YES;
    }else if (range2.location ==NSNotFound){
        currentURL = @"http://www.imc.jhmi.edu/news.html";
        [webView reload];
        return YES;
    }
    return NO;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    webView.scalesPageToFit=YES;
    webView.delegate = self;

    NSString *urlAddress = @"http://www.imc.jhmi.edu/news.html";
    NSURL *url =[NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestObj];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T10:05:30+00:00Added an answer on June 6, 2026 at 10:05 am

    This delegate method webView:shouldStartLoadWithRequest:navigationType: is Sent before a web view begins loading a frame. and it Return Value YES if the web view should begin loading content; otherwise, NO.

    Your method returns NO when currentURL with range1 and range2 not found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.