Elwood
Elwood

Reputation: 288

Open a URL in a certain browser tab/window

From within my Qt application, I would like to open URLs repeatedly in the same browser tab/window. (Kind of "refreshing" this tab programmatically)

Using

QDesktopServices::openUrl(QUrl("http://www.domain.tld"));

opens a new tab/window for every call. Is there a possibility to add a "target=" parameter somewhere?

Upvotes: 7

Views: 2762

Answers (2)

phyatt
phyatt

Reputation: 19112

What you are asking for is impossible to do in the way you imagine it. openUrl() uses the operating system to specify the program to open the argument as mentioned in its documentation.

There might be some workarounds, but none of them will work well, or work on all browsers. It's just that this kind of fine-grained control is likely to be impossible for you.

If you want control of a tab in a browser, you could find the window represented by that tab and close it right before opening the new one. This solution is kind of hacky.

Another hacky solution is to find the HWND of the edit box holding the URL, and to try changing its text using SendMessage(). This won't work on Chrome, however, as it does not use a separate control for the URL window. It might work on Firefox or IE.

The better solution is to make your own web browser you control using the Qt WebKit. It is pretty easy to render a page in it and change the url viewed. The QWebView is an easy to use implementation of the QtWebKit.

Upvotes: 3

Ediolot
Ediolot

Reputation: 521

Maybe you will found this usefull:

You can open the webpage and the reload the active tab.

If you supply the name of the browser as an argument, it'll find and reload the current page

https://unix.stackexchange.com/questions/37258/refresh-reload-active-browser-tab-from-command-line

Upvotes: 0

Related Questions