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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:21:46+00:00 2026-05-12T00:21:46+00:00

I have a very simple Mac Cocoa app that just has a Web View

  • 0

I have a very simple Mac Cocoa app that just has a Web View that loads an HTML file with some CSS and JavaScript. I have hooked up the app delegate to this method:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  NSString* filePath = [[NSBundle mainBundle] pathForResource: @"index" ofType: @"html"];
  NSURL *url = [NSURL URLWithString: filePath];
  [[self.webView mainFrame] loadHTMLString: [NSString stringWithContentsOfFile: filePath] baseURL: url];
}

The index.html file contains the following:

<html>
  <head>
    <title>Hello, World!</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
      jQuery(function($){
        $('h1').fadeOut()
      })
    </script>
  </head>
  <body>
    <h1>Hello, World!</h1>
  </body>
</html>

The style.css file gets loaded correctly, because I set the background to grey in that, so I know it can load other assets from the resource bundle. The javascript code does not get executed. If I open index.html in Safari, the Hello World h1 disappears, as expected. Why doesn’t this happen in the app in my WebView? Do I have to do something to enable JavaScript? The box next to JavaScript is checked in Interface Builder.

The code for this is available at http://github.com/pjb3/WebViewApp

  • 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-12T00:21:46+00:00Added an answer on May 12, 2026 at 12:21 am

    You don’t have to do anything to enable JavaScript; it’s enabled in the WebView by default. And like you said, you can always check in Interface Builder that the JavaScript checkbox is selected.

    What you have to do, though, is make sure that the baseURL you’re specifying is correct (since in the html file you’re referring to jquery.js with a relative URL using just the filename) and that you’ve included the jquery.js file into the bundle resources.

    The code you posted will result in a nil value for the url variable: +URLWithString: expects a valid URL string (that conforms to RFC 2396) as the argument (which the filesystem path you’re providing is not). What you want is +fileURLWithPath:, and you also need to use the filesystem path of the directory where index.html and jquery.js reside, which you can get by removing the filename from the path you’ve got (using NSString‘s -stringByDeletingLastPathComponent:). Here’s how you get the correct baseURL:

    NSURL *url = [NSURL fileURLWithPath:[filePath stringByDeletingLastPathComponent]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 132k
  • Answers 132k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^account/activate$ index.php?route=account/activate&%1 Basically this… May 12, 2026 at 6:29 am
  • Editorial Team
    Editorial Team added an answer You can do it with a correlated subquery or using… May 12, 2026 at 6:29 am
  • Editorial Team
    Editorial Team added an answer After doing some digging I have found the answer to… May 12, 2026 at 6:29 am

Related Questions

On which technological basis would you implement a multimedia app, which has to meet
On my side job as programmer, I am to write a program in C++
On Linux under X11 and using GTK+ you have something called Main Loop. Once
Will a MacBook Air have enough horsepower for occasional development in Ruby? Objective C?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.