I am stuck at an issue, I don't know if its possible or not.
I need to call a HTML page, but the page has some content being loaded via Javascript too and I need to get that also.
Is this some how possible ?
Currently I have used plain: new URL(url).openConnection() and it's not returning that.
Any Help ?
Thanks
To do that you'll need to host a WebView in your application. It can be hidden if you want. Call the webview loadUrl to load the content you want. Handle the WebViewClient onPageFinished so you know all of the content has loaded, and then use the javascript bridge interface (addJavascriptInterface) to pass the HTML back up to the application.
Related
I have a button through which i INVOKE a java method :
<h:commandButton value="My Schedule" action="#{empDutySchedBean.viewMyTask}" rendered="#{welcomeBean.workSchedule}" class="mainLinks"/>
now through this method viewMyTask() i get a List of values returned from the database.
public List viewMyTask()
{
setEmpID((String) session.getAttribute("userName"));
setEmpDuty(ts.getMyTask(getEmpID()));
return empDuty;
}
From here i want tht with the click of a button, the user is redirected to another page and the List data shows up.
I dont understand how to REDIRECT to another HTML page and display the LIST data.
NOTE: --> this button is basically a menu on my webpage. For the other menus i have used an anchor tag. However as you cannot invoke a method using anchor tag, i have used button tag. But because of this, I am not being able to redirect
Some Ways that i think it can be solved are:
use anchor tag instead on button to redirect to the other page AND then use onLoad method of javascript to INVOKE java method
invoke another method after viewMyTask() to perform the redirection.
I dont kw how these methods would work though.
First off, I assume you already know how to return the data Java side, in which case this is really just a javascript question. To do simple post-gets, I usually use Ajax, like so:
new Ajax.Request(myUrlToCall, {
method:'POST',
onComplete: function(transport) {
window.location.replace(theRedirectUrl);
}
});
This will call whatever url you wanted to call Java side, then on the completion of this call, will redirect you to whatever url you want to go to. If you need to send some parameters to the java side, all you need to add is:
parameters:myParamVar,
after the method:'POST' line, and if you want your java side to return the url, then all you'd need to do is send it as json or similar in the response, then do:
window.location.replace(transport.responseJSON["theRedirectUrl"])
Hope that helped!
I have a WebView with an iframe inside. The contents of the iframe do a redirect to another URL that doesn't allow embedding in an iframe. Not a problem, actually, I just want to start the external browser activity in this case instead. The problem is that I can't find a way to intercept the redirection. None of shouldOverrideUrlLoading(), onPageStarted() or onLoadResource() get called for the redirect, hence I get no chance to start the activity.
In the html change the iframe tag to call some javascript function when a redirect happens
example: iFrame src change event detection?
For anyone else with this problem, we found an even more simple solution to this than calling a javascript function. Simply add "target= _top" to the iframe redirect (see http://www.w3schools.com/tags/att_a_target.asp). Then shouldOverrideUrlLoading() will be called in the Android code.
I am working on some javascript injection into m android webview. I am just not completely sure of the syntax it is looking for
I want to call this function in my html page:
$(document).ready(function({...})
I have a webview and javascript interface setup in my app. I also have javascript enabled
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/mydocument.html");
myWebView.addJavascriptInterface(new myJavaScriptInterface(), "jsintector");
myWebView.loadUrl("javascript:ready()");
the javascript:ready() is supposed to be the part in the android that calls the correct function in the html page. What is the proper syntax to access this function? $(document).ready(function({...})
(edit: the javascript is already in the html, I just want to force it to run from the android side)
Try to search before...
Anyway, the simplest way to do this is to do the following:
load the url into a string
inject the javascript into the string
use loaddata to load the html into the webview
I m trying to access JavaScript function from Servlet code. But I'm getting the error shown below.
Here is the code:
out.println("<FRAME src=\"javascript:parent.newWindow('" + URL+ "') \" scrolling=No noresize />");
And this is the error that occurs in JavaScript:
Object does not support this property or method;
You can't access a Javascript function from your servlet code. Javascript executes on the client (= your user's browser) and the servlet code executes on your server (for example Tomcat, JBoss, whatever you're using).
What are you trying to accomplish with your code? I'm sure there's a simpler way to do it than what you just described.
[edited]
I see you just updated your description, so here's my view:
I'm guessing that you want to display a page to the user and when the page is displayed, you want to open a new window which will display another page using the URL parameter to point its address. If this is the case, you should probably just do this in the first page's onLoad() Javascript event using window.open().
There is no newWindow property on a window object (which is what parent references), so this is not unexpected.
Maybe you are looking for the open method instead?
If so, then:
Putting it as the src of an iframe is a very strange thing to do
It will probably be zapped by pop-up blockers
Ok. You try to generate javascript code inside Servlet code. When you do, your code goes to Web browser and it's seen there as a html document with javascript inside. So, your error rather comes from web browser and links to javascript error. Probably it's newWindow method. To open new window you should call window.open() function, I guess.
I have a website loaded in WebView on Android 1.6 and I want to get the HTML-Code of a Site which was generated when the user hits Submit. The parameter get submitted by GET, if that's important.
Then I want to change the HTML-Code and show it to the user, without showing the real Answer-page first.
Maybe I could use onFormResubmission() from WebViewClient? But I really have no idea how.
Thanks for the help!
This is not possible with WebView's API, because you cannot "get the HTML-Code of a Site" that was retrieved by WebView. You are welcome to perform your own HTTP operations using HttpClient and feed the results to WebView via loadData() or loadDataWithBaseURL().