Hi I am very new to java script in android? My problem is my files not loaded in the android assets.
When i run my code i got exception like.
07-08 11:49:10.809: I/chromium(25627): [INFO:CONSOLE(1)] "Uncaught ReferenceError: myFunction is not defined", source: (1)
07-08 11:49:11.100: I/chromium(25627): [INFO:CONSOLE(78)] "Uncaught TypeError: Cannot call method 'getContext' of null", source: file:///android_asset/keyGasGraphBuilder.js (78)
But In my code i have added all the files in the assets.
and also i have added my code.js file in the html page while loading
<script type="text/javascript" src="file:///android_asset/code.js"></script>
and from the code i have call like
duvaltriangle.getSettings().setJavaScriptEnabled(true);
WebSettings setting =duvaltriangle.getSettings();
duvaltriangle.loadUrl("file:///android_asset/Dynamic Ratings - Duval DEMO.htm");
String name = "Duval 2b OLTC Type IIb";
duvaltriangle.loadUrl("javascript:myFunction(\""+name+"\")");
My js file:
Please tell me where i missed. I think i have done all the procedure right way.
function myFunction(name)
{
document.getElementById("demo").innerHTML = name;
}
Use:
duvaltriangle.loadUrl("file:///android_asset/Dynamic Ratings - Duval DEMO.htm");
duvaltriangle.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView view, String url) {
String name = "Duval 2b OLTC Type IIb";
duvaltriangle.loadUrl("javascript:myFunction(\""+name+"\")");
}
});
Because it takes time to load url. So, scripts must be loaded when page finishes loading.
Related
I am trying to use html2canvas on a Shopify product page to convert a div to an imgURL to set as a form value. Whenever I use html2canvas, I get the error:
Uncaught ReferenceError: onLoadStylesheet is not defined at HTMLLinkElement.onload
When I try to pinpoint the error, it just directs me to <!doctype html> highlighted with the message
Each dictionary in the list "icons" should contain a non-empty UTF8 string field "type".
This also prevents the form from posting for some reason.
html2canvas(document.querySelector("#container"), {useCORS: true, logging: false}).then(canvas => {
document.getElementById("imgURL").value = canvas.toDataURL();
});
How do I fix this?
I found the solution, if you are using ScriptTags and loading JavaScript from your own domain then you will get the error, solution is to use the cache=true when creating the ScriptTag and this will load JavaScript from Shopify's CDN and html2canvas works
Here is the code snippet in C# to create a script tag with caching:
dynamic scriptTagBody = new ExpandoObject();
scriptTagBody.script_tag = new ShopifyScriptTag()
{
Event = "onload",
Src = "https://example.com/script.js",
DisplayScope = "all",
Cache = true
};
HttpContent content = new JsonContent(scriptTagBody);
content.Headers.Add("X-Shopify-Access-Token", "MyAccessToken");
string url = "https://yourshop.myshopify.com/admin/api/2021-04/script_tags.json";
await _httpClient.PostAsync(url, content);
ShopifyScriptTag in the above snippet is a simple POJO with those properties
I have JS camera object in codenameone project while I am trying to call that object from a js file its giving me the Uncaught ReferenceError: camera is not defined
error in my chrome browser, while i am trying to upload a image
Below is my codenameone code
camera.set("capture",new JSFunction(){
public void apply(JSObject self, Object[] args) {
Display.getInstance().openImageGallery(new ActionListener(){
#Override
public void actionPerformed(ActionEvent evt) {
String imagePath ="";
if(evt!=null){
imagePath=(String)evt.getSource();
final JSObject uploadedFile = (JSObject)ctx.get("document.getElementById('uploadedFile')");
uploadedFile.set("value",imagePath);
}
}
});
}
});
ctx.set("camera", camera);
Below is my js file where i am getting error for the camera object I used to give window.camera but at that its giving the same above error for capture where capture is the button id which i am using in my html file.
Below is my js file
document.getElementById('capture')
.addEventListener('click', function(){
camera.capture(function(){
var results = document.getElementById("uploadedFile").value;
document.getElementById("uploadedFile").value=results;
})
}, true);
JS camera file is not loaded thats why you are getting this error.
Make sure file is loaded above this code.
structure should be like this-->
file src included
then-->
your script here
I'm guessing you are trying to access HTML5 API's within an embedded browser component. It doesn't have access to all the bells and whistles of HTML5 and might fail. I'm not sure if these will work on the device either although you would have a better chance there than in the simulator.
I'm trying to build a universal rss application for Windows 10 that could be able to download the content of the full article's page for offline consultation.
So after spending a lot of time on stackoverflow I've found some code:
HttpClientHandler handler = new HttpClientHandler { UseDefaultCredentials = true, AllowAutoRedirect = true };
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = await client.GetAsync(ni.Url);
response.EnsureSuccessStatusCode();
string html = await response.Content.ReadAsStringAsync();
However this solution doesn't work on some web page where the content is dynamically called.
So the alternative that remains seems to be that one: load the web page into the Webview control of WinRT and somehow copy and paste the rendered text.
BUT, the Webview doesn't implement any copy/paste method or similar so there is no way to do it easily.
And finally I found this post on stackoverflow (Copying the content from a WebView under WinRT) that seems to be dealing with the same exact problematic as mine with the following solution;
Use the InvokeScript method from the webview to copy and paste the content through a javascript function.
It says: "First, this javascript function must exist in the HTML loaded in the webview."
function select_body() {
var range = document.body.createTextRange();
range.select();
}
and then "use the following code:"
// call the select_body function to select the body of our document
MyWebView.InvokeScript("select_body", null);
// capture a DataPackage object
DataPackage p = await MyWebView.CaptureSelectedContentToDataPackageAsync();
// extract the RTF content from the DataPackage
string RTF = await p.GetView().GetRtfAsync();
// SetText of the RichEditBox to our RTF string
MyRichEditBox.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, RTF);
But what it doesn't say is how to inject the javascript function if it doesn't exist in the page I'm loading ?
If you have a WebView like this:
<WebView Source="http://kiewic.com" LoadCompleted="WebView_LoadCompleted"></WebView>
Use InvokeScriptAsync in combination with eval() to get the document content:
private async void WebView_LoadCompleted(object sender, NavigationEventArgs e)
{
WebView webView = sender as WebView;
string html = await webView.InvokeScriptAsync(
"eval",
new string[] { "document.documentElement.outerHTML;" });
// TODO: Do something with the html ...
System.Diagnostics.Debug.WriteLine(html);
}
Warning recieved : WebKit discarded an uncaught exception in the webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: delegate: The view passed in does not have a window.
dropbox plugin method for getting the files from dropbox inside it i have created an array to get the files and send it to javascript to display the output
getfiles:-
jscallback=[NSString stringWithFormat:#"getFilename(%#)",dropBoxArray];
[self writeJavascript:jscallback];
Method defined in javascript
window.getFilename=function(str)
{
alert(str);
cordova.exec(linkDropboxCB, linkDropboxFail,"DropboxPlugin","getfiles", [""]);
}
getfiles is the method in the dropbox plugin,which contains the above code.
Please help me to remove the warning.
We have a badge script that pulls a json config file and then loads external scripts asynchronously and executes code when they're loaded. The js is stored as a string in the JSON file. To avoid using eval() we're executing the code as follows:
var codeFromJSON = "alert('this far')";
var func = new Function(codeFromJSON);
func();
This works, but returns the following error in chrome, and similar errors in other browsers:
Uncaught SyntaxError: Unexpected token ILLEGAL
At first I thought this had to do with something simple—copying the snippet from the web, etc.—but I've retyped and retested, and still get the same thing...
Any ideas?