Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How can I open a web page in a new window in java?  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my java desktop application i want to open a web page always in new browser window  
If browser is already open, then new browser window should open. Every time it should open a separate window.

i use : Desktop.getDesktop().browse(new URI("http://my.link..."))

but it always opens in another tab in the same window
can I send a browser parameter?
i try :   Desktop.getDesktop().browse(new URI("http://my.link..."+"?%20target=\"_blank\"))
and i got :"java.net.URISyntaxException: Illegal character in query at index 49: http://my link.../?20target="_blank"

thanks



 
Saloon Keeper
Posts: 5035
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try removing the "%20" from the URL.
 
karterdesc sunday
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:Try removing the "%20" from the URL.



hi Tim
I tried  : Desktop.getDesktop().browse(new URI("http://my.link..."+"? target=\"_blank\"))
and i got :"java.net.URISyntaxException: Illegal character in query at index 39: http://my link.../? target="_blank"

for  Desktop.getDesktop().browse(new URI("http://my.link..."+"?target=\"_blank\"))
i got :"java.net.URISyntaxException: Illegal character in query at index 46: http://my link.../?20target="_blank"
 
karterdesc sunday
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks like java with Desktop.browse () can not transmit browser parameters
and yet in java there is no way for this?
 
karterdesc sunday
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I thought the question I put is simple
but it does not seem to be, anyway, I hope someone gives a look and tell me a solution
 
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether a new page opens in a new tab or in a new window is a browser setting. If I don't miss my guess, you may not be able to override it. And if so, would it not be rather unfriendly to do so? Would you like software that changes your browser settings?
 
karterdesc sunday
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Opening a webpage in a tab or window is a dynamic behavior option for the browser, for example javascript controls this (the _blank parameter means new window) I can not believe the native java can not do this
 
Bear Bibeault
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

karterdesc sunday wrote:Opening a webpage in a tab or window is a dynamic behavior option for the browser, for example javascript controls this (the _blank parameter means new window) I can not believe the native java can not do this


Incorrect -- a target of "_blank" (which is HTML, not JavaScript) causes either a new window or new tab to open depending upon the browser settings. Neither HTML (nor JavaScript) can override this setting.
 
karterdesc sunday
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok assuming that the browser is set to open the web page in a new window every time (I checked this with a shortcut where I put a url with and without _blank target) then why in the example presented by me above the web page always open in a new tab in the same window?
in other words if the browser is set to open new windows, what code to use in java to keep this?
 
Rancher
Posts: 3746
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide a link that when copy and pasted into the browser will result in a new window opening?
That is essentially what you are trying to achieve.
I can't get it to do it.
 
Tim Moores
Saloon Keeper
Posts: 5035
134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I tried  : Desktop.getDesktop().browse(new URI("http://my.link..."+"? target=\"_blank\"))
and i got :"java.net.URISyntaxException: Illegal character in query at index 39: http://my link.../? target="_blank"

for  Desktop.getDesktop().browse(new URI("http://my.link..."+"?target=\"_blank\"))
i got :"java.net.URISyntaxException: Illegal character in query at index 46: http://my link.../?20target="_blank"


Print the URL out in full so that you know what the character at those positions are. What's more, it doesn't look like that code should even compile, because the string is not terminated by double quotes. So apparently we're not seeing the full code.
 
karterdesc sunday
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the url was obtained by concatenation as follows:
url = elem [1] + "?% 20target = \" _ blank \ "";
where elem [1] was obtained by querying a database

I made this concatenation as follows:
url = elem [1] + "?% 20target = '_ blank'";

and I have no error but the web page always opens in a new tab
((is Bear Bibeault right: so the browser is set))

and yet there is no way to force the browser to open the web page in a new window?

thank you very much for any clarification
 
Sheriff
Posts: 23867
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why you put a blank (or %20) after the ? in that URL. It isn't usual to have a blank there, so perhaps the browser is ignoring the parameters after the ?
 
Dave Tolls
Rancher
Posts: 3746
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of curiosity, does anyone know when the target attribute takes effect?
I always thought the browser reacted to it before sending the request...though I will admit to having absolutely no evidence for that at all!
 
Rancher
Posts: 3312
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the target= option is to control the browser, not part of a URL to connect to a site.  
Is there a way to send options to the browser on the commandline?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!