Controlling Website Within Xcode/ Swift Uiwebview
I have created a very simple app which directs the user to a web app... one of the pages within the app allows you to search store stock for various different stores (store number
Solution 1:
Check this question and responses:
Calling Javascript using UIWebView
- Create a js method to receive your barcode.
When the page is already loaded, you can call it by using stringByEvaluatingJavaScriptFromString.
let codebar = "34244342342424234" webView.stringByEvaluatingJavaScriptFromString("methodName("\(codebar)");")
Update
I used this method some time ago: evaluateJavaScript in WKWebView, this example loads a jQuery and then change the background:
var navigator : WKWebView!
funcrunJS(js:String) {
navigator.evaluateJavaScript(js) {
res, error inprint(res ??"no res", error ??"no error")
}
}
@IBActionfuncchangeBackground(_sender: Any) {
navigator.evaluateJavaScript("jQuery('body').css('background', 'magenta!important')") {res, error inprint(error ??"no error buton 1")}
}
@IBActionfuncloadJQuery(_sender: Any) {
//Load jQuery library using plain JavaScript
runJS(js: "(function(){ "+"var newscript = document.createElement('script'); "+"newscript.type = 'text/javascript'; "+"newscript.async = true; "+"newscript.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'; "+"(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(newscript); "+"})();")
}
Post a Comment for "Controlling Website Within Xcode/ Swift Uiwebview"