I want to make a simple program that ask you which browser you want to use.
When you'll click on a link (email or pdf for example), a program will appear instead of the browser and will ask you which browser you want to use.
First : in which code it's the best to write this?
Secondly : How to open the program and not the browser?
I need a bit of help to write this, because i don't know how begin
This is tricky. There is no uniform event for "User clicks on url" that spans all applications.
The most straightforward solution would be to create your application and register it as the default browser.
Personally I would be annoyed by having to select a browser each time I click a link so I would probably make a helper application that when it starts remembers the current default browser and then registers the browser selector as the default. And when the helper closes it would restore the default browser.
My Java is quite rusty but I think this should be possible in either language. Maybe a little trickier in Java due to the lack of a dedicated executable for your application.
For C#:
This will open the url in the default browser:
string url = "http://google.com/";
System.Diagnostics.Process.Start(url);
This will open the url in the specified browser:
System.Diagnostics.Process.Start(#"C:\Program Files\Mozilla Firefox\firefox.exe", url);
There will be an error if the browser does not exist.
Related
I have a daily task of downloading a Report[an Excel file] . Before I click the download button, certain fields have to filled and some checkboxes need to be checked. On clicking the executable file on my desktop, the whole process must happen in one go. I m looking for an opensource solution either in Javascript or JQuery to automate this download.
After the information you shared, I'm afraid you'll have to write an application in a desktop programming language. It doesn't really matter which language you use, and I'm not going to make suggestions since I don't know your situation.
The fun part will be determining what the browser does. The browser will basically send a HTTP request, either a POST or a GET (I don't know which one it is since I don't know the page). You'll have to open your developer tools in your browser, check what it sends and how it sends it and where it sends it, then recreate that using your language of choice. You then need to read the response and turn it into an excel file.
Now, this is quite challenging and I don't know how experienced you are. If you are willing to give up the desktop executable requirement, you can write a Greasemonkey script (in Firefox) or a Chrome extension (for Chrome, duh) which can automate this from the browser. Both use Javascript and are arguably easier to create since you don't need to recreate the HTTP request or reverse engineer what the browser does.
Are java applets capable of opening new browser windows and retrieving their end URL?
Are java applets capable of opening new browser windows and retrieving their end URL?
No, and it is really none of the applet's business. It is a security thing.
Imagine you control an applet that opens an innocuous window. I get bored with that and reuse the window to surf over to BigBustyBabes.com instead. That final URL is not something I (as a user) would want your applet to know.
This link might help with opening a new URL, but from the same browser window. However assuming that you can reach the path where a browser is, you could easily run it. However I think this can be done easier with javascript, at least the part with retrieving the end URL, javascript seems to be the solution.
For opening a new window with javascript: window.open(URL,name,specs,replace).
For retrieving a URL with javascript use document.URL
Although I've been programming for a few years I've only really dabbled in the web side of things, it's been more application based for computers up until now. I was wondering, in java for example, what library defined function or self defined function I would use to have a program launch a web browser to a certain site? Also as an extension to this how could I have it find a certain field in the website like a search box for instance (if it wasnt the current target of the cursor) and then populate it with a string and submit it to the server? (maybe this is a kind of find by ID scenario?!)
Also, is there a way to control whethere this is visible or not to the user. What I mean is, if I want to do something as a background task whilst the user carries on using the program, I will want the program to be submitting data to a webpage without the whole visual side of things that would interrupt the user?
This may be basic but like I say, I've never tried my hand at it so perhaps if someone could just provide some rough code outlines I'd really appreciate it.
Many thanks
I think Selenium might be what you are looking for.
Selenium allows you to start a Web browser, launch it to a certain website and interact with it. Also, there is a Java API (and a lot of other languages, by the way) allowing you to control the launched browser from a Java application.
There are some tweaking to do, but you can also launch Selenium in background, using a headless Web browser.
as i understand it you want to submit data to a server via the excisting webinterface?
in that case you need to find out how the URL for the request is build and then make a http-call using the corresponding URL
i advice reading this if it involves a POST submit
Is it possible to programmatically start an application from Java and then send commands to it and receive the program's output?
I'm trying to realize this scenario:
I want to access a website that uses lots of javascript and special html + css features -> the website isn't properly displayed in swt.browser or any of the other of the available Browser Widgets. But the website can be displayed without any problems in firefox. So I want to run a hidden instance of firefox, load the website and get the data. (It would be nice if FF can be embedded in a JFrame or so..)
Has anybody got an idea how to realize this?
Any help would really be appreciated!
EDIT: The website loads some Javascript that does some html magic and loads some pictures. When I only read the html from the website I see nothing more than some JavaScript calls. But when the website is loaded in a Browser, it displays some images overlayed with text. That's what I'm trying to show the user of my app.
To start Firefox from within the application, you could use:
Runtime runtime = Runtime.getRuntime();
try {
String path = "/path/to/firefox";
Process process = runtime.exec(path + " " + url);
} catch (IOException e) {
// ...
}
To manipulate processes once they have started, one can often use process.getInputStream() and process.getOutputStream(), but that would not help you in the case of Firefox.
You should probably look into ways of solving your specific problem other than trying to interact directly between your application and a browser instance. Consider either moving the whole interface into a Java gui, or doing a web app from the ground up -- not half and half.
See this article - it will teach you how to start a process, read its output and write to its input stream.
However this solution may be not be the best for your problem. What kind of data do you need to get from the Web Page? Would it be better to read the html with an HTTP GET and then parse it with an Html parser?
If you have a text-mode browser available (like links2 on linux) you might want to see how well that can render the page. For example, the command "links -dump http://someurl.com" will format the page as text and exit immediately, resulting in output that might be easily parseable using the methods that Ray Myers and kgiannakakis suggest.
If the website is static, you could use a web scraper like Jericho to load the URL, parse the HTML and wander your way through the DOM to the info you need.
Although a similar feature to what you describe is planned for FireFox in the future, it is not available yet. The feature is dubbed TaskFox, and from the linked wiki, "its aim is to allow users to quickly access information and perform tasks that would normally take several steps to complete."
News of the upcoming TaskFox feature just broke today, in fact. Perhaps you should consider a career being a psychic instead of a programmer.
Consider the most excellent wordle tag cloud generator:
http://www.wordle.net/create
Entering text into the "textform" textarea and clicking the go button starts up the wordle java applet on that page. No traffic goes back to the server.
How can I cause this to happen programmatically? No hack too cheap!!
background for this question:
"tag cloud" generators?
If you mean starting it programmatically from a browser page, you can use the same type of JavaScript that that page uses, which calls the function Wordle.t() to start the applet.
If you want to call it from a Java program, you can download the Wordle.class or jar file yourself, and call the functions directly.
I'm the creator of Wordle.
In case anyone finds this page in the future, I thought it would be useful to explain that Wordle invokes its applet by constructing an applet tag with a huge <param> containing a sanitized version of whatever text you pasted in. It is the cheapest hack imaginable.