Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda