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 3227662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:36:04+00:00 2026-05-17T16:36:04+00:00

I am loading an existing html document in a UIWebView with iOS 3.2 on

  • 0

I am loading an existing html document in a UIWebView with iOS 3.2 on an iPad. After the HTML loads I run the following code to insert jQuery into this document:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSLog(@"load complete");
if (webView == self.contentView) {

    [self.contentView stringByEvaluatingJavaScriptFromString:
     @"var headID = document.getElementsByTagName(\"head\")[0];"    
     "var newScript = document.createElement('script');"
     "newScript.type = 'text/javascript';"
     "newScript.src = 'jquery-1.4.2.min.js';"
     "newScript.onload=window.location.assign(\"fj://jquery\");"
     "headID.appendChild(newScript);"];

}
NSLog(@"inserting jquery");
}

Then the following code runs when the bogus request for fj://jquery comes:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"URL: %@", [[request URL] scheme]);

if ([[[request URL] scheme] compare:@"fj"] == NSOrderedSame) {
    NSString * command = [[request URL] host];

    if ([command compare:@"jquery"] == NSOrderedSame) {
        NSLog(@"got jquery");   

        NSString * offsetStr = [self.contentView stringByEvaluatingJavaScriptFromString:@"$('P:last').offset().top;"];

        NSLog(@"offset: %@", offsetStr);            

    }
    return NO;
}

return YES;
}

As far as I know, this is all pretty much the standard way to insert JS into a loaded HTML in UIWebView.

However, my problem is, that my jQuery code does not run and returns an empty string.

I have used the same code with success in a prototype test app. Now in the real production app, it does not work anymore.

Here is what I have done to isolate the problem, with no success:

  • jquery-1.4.2.min.js is in the same directory as the loaded HTML
  • the webview is not nil
  • when I load the same HTML inside safari and execute the JS code inside the JS console, everything runs as expected

A hint that I have is: the stylesheet.css file in linked in the original document is corrupt (0 KB) but I don’t have any control on that. That’s how I receive the package form the client. I should be able to work with it.

  • 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-17T16:36:04+00:00Added an answer on May 17, 2026 at 4:36 pm

    I don’t know why but the exact problem was apparently that the script elements did not get activated in the first loaded HTML file. Following files were able to use the scripts with no problems.

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

Sidebar

Related Questions

When loading XML into an XmlDocument, i.e. XmlDocument document = new XmlDocument(); document.LoadXml(xmlData); is
What is Lazy Loading? [Edit after reading a few answers] Why do people use
I'm loading a SQL Server 2000 database into my new SQL Server 2005 instance
When loading a page for the first time (!IsPostback), I am creating a button
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Some loading routines in my program takes to long to complete. I want a
I'm dynamically loading user controls adding them to the Controls collection of the web
The problem: Loading an excel spreadsheet template. Using the Save command with a different
I am actually loading a page as a modal dialog box as window.showModalDialog(url.aspx). The
I'm loading an image from a file, and I want to know how to

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.