Current URL in CordovaWebView - java

Can anybody tell me how to get the current URL of CordovaWebView when using Phonegap (Cordova)?
I want to do something like this in Java when the URL changes to the one I want:
if(current_url_cordova_webview=="http://www.google.com"){
alert("Yes");
}else{
alert("No");
}
Many thanks!

I hope you mean JavaScript and not java. document.URL will get you the current URL in JS.

Thank you for the response. I managed to do it myself by creating a custom Webview and checking the url in onPageFinished.

Related

Beginner to API Json - Attempting to understand URL output

I am using FME to get output from the following: https://coronavirus.data.gov.uk/developers-guide
I am just a beginner and is first time I want to write this up. To generate an Output URL from this with the relevant columns, can anyone explain what I need to get the request URL. I am using GET as the HTTP method
An example of a url i get some data out of is - https://soa.smext.faa.gov/asws/api/airport/status/SFO
But when i try with the links below which i tested does not get any output https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=nation;areaName=england&structure=%7B%22name%22:%22areaName%22%7D
https://api.coronavirus.data.gov.uk//v1/data?filters=areaType=nation;areaName=england&structure={"date":"date","areaName":"areaName","areaCode":"areaCode","newCasesByPublishDate":"2020-07-07","cumCasesByPublishDate":"2020-08-08","newDeathsByDeathDate":"2020-02-06","cumDeathsByDeathDate":"2020-06-09"}
This is a better link for you to try out.
https://api.coronavirus.data.gov.uk/v1/data?filters=areaType=nation;areaName=england&structure={%22date%22:%22date%22,%22areaName%22:%22areaName%22,%22areaCode%22:%22areaCode%22,%22newCasesByPublishDate%22:%22newCasesByPublishDate%22,%22cumCasesByPublishDate%22:%22cumCasesByPublishDate%22,%22newDeaths28DaysByDeathDate%22:%22newDeaths28DaysByDeathDate%22}
Took me a while to suss it out.

What to post in HTTP POST

I am working on an android app which helps the user login. The site which I want to login is this
I have been now searching for 2 days straight but haven't found myself any answer as to what all I should post.
The problem that I am facing is what all parameters should I post ? I have tried every possible combination of hidden and non-hidden and also tried with cookies.
It would be really kind of you if you could give me the list of the parameters that I should include in my request.
As of now , this is my code
Document docl = Jsoup.connect("http://erp.mitpune.com/AdminLogin.aspx")
.data("__VIEWSTATE","/wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD")
.data("txtPassword","*******")
.data("__LASTFOCUS","")
.data("__EVENTTARGET","")
.data("__EVENTARGUMENT","")
.data("__VIEWSTATE","/wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD")
.data("__VIEWSTATEGENERATOR","B8B84CAE")
.data("hdnMsg","")
.data("txtUserId","********")
.data("btnLogin","Login")
.method(Connection.Method.POST).post();
I am using jsoup,on android studio, but just the list would help me a lot.
Thanks in advance
txtUserId and txtPassword
posted to Adminlogin.aspx
inside form1
so form1.txtUserId and form1.txtPassword
This is a quick output of data variables by Fiddler Chrome Extension
ScriptManager1: UpdatePanel1|btnLogin
__ASYNCPOST: true
__EVENTARGUMENT:
__EVENTTARGET: btnLogin
__LASTFOCUS:
__VIEWSTATE: /wEPDwUINDA4MDU2ODdkZGYVkCI+Zarbu9B42es/RUu7ZNbD
__VIEWSTATEGENERATOR: B8B84CAE
hdnMsg:
txtPassword: sasasa
txtUserId: jajas
Seems like _ASYNCPOST and ScriptManager1 are not in your post variables .

How to call a server side java method from HTML using javascript?

I want to know how to call a java method from HTML (I Use HTML5) using java script. I tried using Applets but this didnt work. I have to take the value of a drop down box in the html file and take it to a java method to process it.
What you are looking for is AJAX. It's extremely easy to do with a library such as jQuery
$.get('your/servlet').done(function(data) {
// data is the data returned by the request
});
Jabsorb implements this: http://code.google.com/p/jabsorb/
You will want to do this with a request to a servlet. Like ThiefMaster said, Ajax is a good way to go
Here's a quick article to get you started: http://javapapers.com/ajax/getting-started-with-ajax-using-java/

Why getRequestDispatcher("/index.jsp").forward() dont work with JSP?

I try to redirect my page to another using request.getRequestDispatcher("/index.jsp").forward(request, response); . But it dont work. Why? But when I change it to response.sendRedirect it work fine.
I think the problem might be because of not using relative url.
You can try like this
request.getRequestDispatcher("index.jsp").forward(request, response);
I think you do need the forward slash with the JSP filename.
This is just a small possibility (need more info) - but do you have an init() method in your servlet?
If you do, you must call super.init(servletConfig) as the first line of your init() method, or you might get a NullPointerException when you try to forward.

simple example of native app passing string to website?

Can somebody give a simple example for java code of a native app passing a string to a website?
For example: when a string has the value Hello everybody, the text Hello everybody should get pasted into the Google search field.
For the most simple use, you can try:
public static void browseURL(Activity activity, String url)
{
try
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);
}
catch (Exception e)
{
message(activity, "Sorry, failed to view the desired page.");
}
}
and then call:
browseURL("http://www.google.com/search?q=Hello+World")
Do you want to fill the fields and submit them? If so, just do the request with the request parameters filled, and parse the response given by the server. Look into Apache HttpClient.
You don't actually have to add text to the Google search field explicitly. You can send a URL with a query string.
Depending on the website the query string will always be different. For Google it is http://www.google.ca/search?q=something . Anything after a ? is considered a query string which any good web developer will include in a webpage. That query string takes custom commands in the form of ?command=query for command&command2=query for command 2.
Since this is tagged blackberry, I assume you want to implement a blackberry app, and you don't explicitly explain what you want to do, so you have two options,
Invoke the browser
On that page it describes how to open a browser session. So within the
browserSession.displayPage("http://http://www.google.ca/search?q=searching%20for%20something");
If you need a class for URL encoding, let me know and I'll send one your way.
Http Request to pull the html of the webpage into the code. To do that, you'll have to look at my blog this week as I'll be posting a full in code network class either tomorrow or tuesday, which I'll edit this post to contain a link to.
OR you can send me a message if you need it NOW and I can email the non-cleaned up code to you.

Categories

Resources