Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Including jQuery library in JavaScriptCore

I am trying to use jQuery functions in JavaScriptCore, so I have executed the jQuery library as a script in my JSContext. However, after I do that, I still can't access any jQuery functions. Here's a stripped-down version of my code in a Xcode playground:

import JavaScriptCore
let context = JSContext()

//Evaluate JQuery library in context:
do {
let libString = try String(contentsOf: URL(string: "http://code.jquery.com/ui/1.9.2/jquery-ui.js")!, encoding: .utf8)
context?.evaluateScript(libString)
} catch (let error) {
    print("Error while processing URL: \(error)")
}

//Access variables defined by JQuery library:
 print("'$' in context is defined as: \(context?.objectForKeyedSubscript("$"))")
 print("'jQuery' in context is defined as: \(context?.objectForKeyedSubscript("jQuery"))")

This prints:

'$' in context is defined as: Optional(undefined)

'jQuery' in context is defined as: Optional(undefined)

If I had included the library correctly, those would be defined as functions. What have I done wrong? Should I even be using JavaScriptCore to gain jQuery functionality?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You should include jQuery library:

NSString *commond = @"window.onload=function(){var jq=document.createElement(\"script\");jq.setAttribute(\"src\",\"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/js/lib/jquery-1.10.2.js\");document.getElementsByTagName(\"head\")[0].appendChild(jq);window.setTimeout(\"exec()\",1000)};function exec(){document.write($(\"body\").get(0))};";

[self.webView stringByEvaluatingJavaScriptFromString:commond];
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!