java - open url in chrome browser only

本秂侑毒 提交于 2020-01-29 13:29:31

问题


I have an url, I am trying to open that url in web view of JavaFX but the content was not compatible with web view. It's only compatible to the chrome and firefox. So I would like to open that Url in chrome browser only instead of opening it in web view. is it possible?(I don't want to open it in default browser.)

I tried the below code but we got the error as "Cannot run program "chrome": error=2, No such file or directory".

Runtime.getRuntime().exec(new String[] { "Chrome", "http://goo.gl/EsomR0" });      

thanks,


回答1:


Runtime.getRuntime().exec(new String[]{"cmd", "/c","start chrome http://goo.gl/EsomR0"});

This worked for me.

-- Edit: Only worked on Windows




回答2:


You'll need to use chrome.exe on Windows. On Linux this works for running Chromium:

Runtime.getRuntime().exec(new String[] { "chromium-browser", "http://example.com/" });

Obviously it's not going to work for Chrome (or Windows), but we're talking about the principle. Another possibility is that Chrome may not be installed. Try running it from the command line. If it doesn't work there, it's not going to work in Java. Another problem could be that you capitalized "Chrome".




回答3:


I have tried following for android to open URL only in chrome and it worked for me:

"googlechrome://navigate?url=" + url


来源:https://stackoverflow.com/questions/24239046/java-open-url-in-chrome-browser-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!