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

  • SEARCH
  • Home
  • 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 6054511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:09:41+00:00 2026-05-23T08:09:41+00:00

I have an HTML that says the following: <html> <head> <meta name=viewport content=width=320/> <script>

  • 0

I have an HTML that says the following:

<html>
<head>
    <meta name=viewport content=width=320/>
    <script>
        function imageClicked(){
            var clicked=true;
            window.location="/click/"+clicked;
        }
        </script>
</head>
<body>
    <center><h1>This is Page One</h1></center>
    <center><a href="javascript:void(0)" onMouseDown="imageClicked()"><IMG SRC="divers-circle.jpg">
        </a></center>
       </center><br><br>
    <center>Scuba divers</center>
</body>
</html>

The HTML is properly loaded to a UIWebView, since it is a local file:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:((WebPageObj *)obj).webPath ofType:@"html"]isDirectory:NO]]];


    webView.dataDetectorTypes = UIDataDetectorTypeAll;

Now, when I click the image, it recognized the click, but how can I implement an action within Xcode, for example, open another view or an alert?

BTW, I did this based on a tutorial that explains some concept, here is the link:
http://www.codeproject.com/KB/iPhone/iPhoneDevReader.aspx

However, it created the HTML within Xcode, and in my case, I loaded the HTML, therefore, I need to somehow read the script within the HTML to include the following:

if ( [request.mainDocumentURL.relativePath isEqualToString:@"/click/false"] ) {    
        NSLog( @"not clicked" );
        return false;
    }

    if ( [request.mainDocumentURL.relativePath isEqualToString:@"/click/true"] ) {        //the image is clicked, variable click is true
        NSLog( @"image clicked" );

        UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"JavaScript called" 
               message:@"You've called iPhone provided control from javascript!!" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
        [alert show];
        [alert release];
        return false;
    }

    return true;
}

What method will help me to do that? and where Shall I put it since I am using a ScrollView, and then loading the WebView when the page is called.

Thanks in advance.

  • 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-05-23T08:09:41+00:00Added an answer on May 23, 2026 at 8:09 am

    You need to set a delegate for your UIWebView.

    If you set a delegate for your UIWebView the following method will be called everytime your web view sends a request:

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
        NSURL *url = [request URL];
        if (navigationType == UIWebViewNavigationTypeLinkClicked) {
                if ([[url scheme] isEqualToString:@"click"]) {
                   // do whatever you want here to happen after the click
                }
                return NO;
        } else {
           return YES;
        }
    }
    

    To make it as easy as possible change your html to the following (no Javascript needed):

      <html>
        <head>
            <meta name=viewport content=width=320/>
        </head>
        <body>
            <center><h1>This is Page One</h1></center>
            <center><a href="click://"><IMG SRC="divers-circle.jpg"></a></center>
            <br><br>
            <center>Scuba divers</center>
        </body>
        </html>
    

    When the image is clicked, the following is happening:

    1. The WebView sends a request with the URL “click://”.
    2. The UIWebView delegate’s method webView:shouldStartLoadWithRequest:navigationType: is being called
    3. the 2 “if” clauses in this method evaluate to “YES” because the request happened after a click (navigationType == UIWebViewNavigationTypeLinkClicked) and the URL’s scheme is “click”

    You find more about the UIWebViewDelegate protocol here.

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

Sidebar

Related Questions

I have the following code that works: <script type=text/javascript> $(document).ready(function() { // Initialise the
Ok, so as the title says, I have an HTML page that I fetch
I have the following simple script on a page <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I am following this routing tutorial for Ruby on Rails: http://guides.rubyonrails.org/routing.html It says that
I have the following CGI script that launches a module that creates a PNG
I have HTML that includes symbols such as the Trademark TM as superscript (™).
I have HTML that I need to extract a part number from, the HTML
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have some HTML that looks like this: <ul class=faq> <li class=open> <a class=question
I have some HTML that displays fine on FireFox3/Opera/Safari but not with IE7. The

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.