0

I am using this code in a jbutton to open a webpage from my java application.

try {
         //Set your page url in this string. For eg, I m using URL for Google Search engine
         String url = "http://www.google.com";
         java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
       }
       catch (java.io.IOException e) {
           System.out.println(e.getMessage());
       }

Though, when i click the button twice, it opens a new tab.

It will eventually be used in a loop to open different websites upon click.

is there anyway to stop it from opening a new tab and just open the next webpage on the current tab?

or close out the last tab before opening a new tab?

5
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by peter_budo
0

You should create a boolean and set it true when you open a webpage. Then, when you try to open it again, test to see if it is true. If it is, don't open the page. If not, go ahead and run the code.

0

This is a personal opinion!
I would prefer an application to open a new TAB instead of a new browser WINDOW.
Especially if your code is in a loop.
I absolutely HATE "web bombs"!!!

0

Though, when i click the button twice, it opens a new tab.

It will eventually be used in a loop to open different websites upon click.

is there anyway to stop it from opening a new tab and just open the next webpage on the current tab?

or close out the last tab before opening a new tab?

You would need to use library such as WebDriver or Selenium

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.