I'm working on an iOS app with an UIWebView. The webpage displayed in the UIWebView is working fine when displayed in the Safari app on iOS, but when it is displayed inside an UIWebView nothing happens when tapping the "Sign in" button: http://www.bnpsolutions.com/Common/Login_Mobile.aspx.
Does someone know why?
You can download my small iOS example project here:
http://uploads.demaweb.dk/WebView.zip
EDIT1:
I've changed the WebView to display a simple page which just including jQuery: http://uploads.demaweb.dk/WebView2.zip.
The error message is:
WebView[13623:11703] JavaScript exception: (/ajax/libs/jquery/1.7.2/jquery.js):5187 - SYNTAX_ERR - SYNTAX_ERR: DOM Exception 12
Line:
(function(){
Why are the UIWebView not able to load jQuery?
Well, using this code to debug your UIWebView i found 2 exceptions in your javascript related to the resource /WebResource.axd. Check that and I hope it result useful.
I would suggest defining the delegate methods:
– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:
– webView:didFailLoadWithError: /* especially this one!! */
and put some NSLog traces there so that you can see what is happening. It is possible that Safari is more resilient to errors (or handles it in a friendlier way) than UIWebView, hence the difference in behavior. But you should check it directly in your app...
With regards to the error message generated - the UIWebView is indeed able to load jQuery - the message you're getting about the exception (based on the link in the comments about how debugging the UIWebView is hooked up) occurs when the exception is raised - whether the exception is caught or not.
That particular function in jQuery has a try/catch near the beginning of the function that purposefully tries to raise an exception (and catch it).
Try this code to see what I mean:
NSString *htmlString = #"<html><body>Hello World I am a <b>browser</b><script>(function(){try {var a=undefined; a();} catch (err) {} }());</script></body></html>";
[uiWebView loadHTMLString:htmlString baseURL:nil];
Whether the try/catch is there or not, the exception will be reported.
Related
I've used Notifications working on a JavaScript app and It's very useful when you don't have to be all the time looking at the app when something important needs to be acknowledged. I tried to replicate some work on Dart but a reference error is shown on compiled to JS Chrome.
Do you know if It's going to be implemented for Chrome soon? or is It going to remain experimental?
Thanks in advance
This is the function which tries to call Notification API. Without Notification line, everything works, when I add Notification line I get this error "Uncaught ReferenceError: requestPermission is not defined" running the code as JavaScript. (I am importing 'dart:html')
void revisarInput() {
if ( valorLogin != '' ) {
indicador = true;
_ws.send( Util.formatearJsonSocket( 'loginPwd', { 'pwd': int.parse( valorLogin )}));
}
Notification.requestPermission();
}
This was a bug in dart2js, https://code.google.com/p/dart/issues/detail?id=22483 and is fixed for Dart 1.9.
This page says
https://developer.chrome.com/apps/notifications
Stable since Chrome 28
I basically want just to listen for 'onbeforeunload' to make sure the user won't receive 'connection lost' error messages from my ajax calls. i therefore registered an event and simply set a variable to true that i know to not bother the user with further error messages:
window.onBeforeUnload.listen((BeforeUnloadEvent e){
isUnloading = true;
});
in Dartium this works, after running dart2js i get a javascript alert with 'false':
according to related questions, to set the text I would have to set e.returnValue = 'Prompt'; - but what should i do if I do NOT want to show any dialog? - according to the MDN the prompt is shown for every non-void return value.. but how can i set returnValue to void? (null is not working) - is this a bug, or am i doing it wrong? (dart sdk 1.0.0.7)
There seems to be no way to prevent this dialog in Chrome if you subscribe to onBeforeUnload.
You can try the onPageHide event (works in Chrome, may not work in other browsers).
so I'm working on an application that uses webview to display data. At the moment i'm trying to get data from, and send data to the webview. It seems that getting data from the webview works fine, but sending data back to the webview forms the problem.
I use fireEvents and Eventlisteners to communicat. It looks somethhing like this:
webview : index.html
// declared at the beginning of the html file
Ti.App.addEventListener('sendToWebview', function(data) {
alert('alert in webview');
});
// fires when button is pushed
function onClick(){
Ti.App.fireEvent('sendToTi', { "someDataToTi" });
}
app.js
Ti.App.addEventListener('sendToTi', function(data) {
alert('alert in Ti');
Ti.App.fireEvent('sendToWebview', { "someDataToWebview" });
});
What works is the sendToTi event. here i always get the alert. What doesn't seem to work all the time is the sendToWebview event. The weird thing is that is sometimes seem to work, other times not and even when I go back to the code that worked, it seems to not work anymore.
What am I doing wrong? is there a way to make it work?
Your 'sendToTi' is correct. But you can't send events to the WebView in that way.
To execute JavaScript (which is sending events) in your WebView you can use
webview.evalJS('someJSFunction(with, parameters, for, instance);');
webview.evalJS('alert("Hello World!");');
There is no need of EventListeners (especially no app-wide event listeners).
I'd like to do the equivalent of chrome.tabs.onUpdated in Firefox. tabs.on('ready', function(tab){}) does not work because it does not detect the back button. How do I fire an action on every page load such that it also detects the back button using the Firefox SDK?
You'd have to use require('window-utils').WindowTracker to all windows, filter for browser windows with the require('sdk/window/utils').isBrowser(window) method, then listen to click events on the back button.
It's currently impossible, but will be possible in a future version of Firefox:
https://github.com/mozilla/addon-sdk/commit/e4ce238090a6e243c542c2b421f5906ef465acd0
A bit of a late answer, but for anyone reading this now (from 2016), it is now possible to do using the SDK!
Using the High-Level API tabs, you need to listen for the pageshow event. (More about this on MDN)
An example:
tabs.on('pageshow', function(tab) {
// Your code here
})
It is very similar to the load and ready events, the main difference being that is is also fired when a page is loaded from BFCache (which it is when the back button is pressed).
I think the following snippet gives the functionality of chrome.tabs.onUpdated
var tabs = require("sdk/tabs");
tabs.on('ready', function(tab){
console.log(tab.url);
});
Before I deem my weak-long custom re-implementation of UITextView (using an UIWebView in designMode) useless, is there any way to handle/cancel javaScript onKeyUp, etc. events?
AFAIK there is only messaging via -shouldLoadRequest: & stringByEvaluatingScriptWithString:. However, these calls are asynchronous and the javaScript event handler has already exited it's function by the time stringByEvaluatingScriptWithString: is performed thus event cancellation methods do not work.
If not for this capability, implementing shouldReplaceCharactersInString: seems impossible. :(
Maybe you can check my open source implementation of a "safari like" browser :
https://github.com/sylverb/CIALBrowser
In this one, I did reimplement the long tap handling, and to disable the standard one, I use this :
- (void) webViewDidFinishLoad:(UIWebView *) sender
{
// Disable the defaut actionSheet when doing a long press
[webView stringByEvaluatingJavaScriptFromString:#"document.body.style.webkitTouchCallout='none';"];
[webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.style.webkitTouchCallout='none';"];
}