7

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?

Elwood
  • 268
  • 4
  • 9
  • Hi Elwood, did you ever find a solution to this? I have the exact same problem: http://stackoverflow.com/questions/15116760/open-a-web-page-from-a-desktop-app-repeatedly-in-same-window – sipickles Feb 28 '13 at 10:57
  • Sipickles: Sorry, no. It seems it is just not possible. I was thinking about creating a local HTML file with `` in it and then overwriting this file on demand. But I did not try that yet and this approach probably has some downsides. – Elwood Mar 07 '13 at 16:57
  • I'm looking for the same thing (open in same tab) but preferably in Qt5. But I would also take a Qt4 solution. – amenthes Mar 16 '15 at 10:03
  • Do any browsers even offer this feature? – MrEricSir Mar 22 '15 at 00:03
  • I am not entirely sure. From within the browser, you can use the anchor tag's `target="something"` attribute. All Links with the same attribute value will open in the same tab / frame / window. I wasn't sure if there was a way to trigger the same thing programmatically. But I guess there's no way. – amenthes Mar 23 '15 at 10:35

2 Answers2

3

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.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
phyatt
  • 18,472
  • 5
  • 61
  • 80
  • Thanks phyatt. I'd rather not want to duplicate existing browser functionality by pulling in QtWebKit. – Elwood Nov 05 '12 at 16:32
0

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

Community
  • 1
  • 1
Ediolot
  • 501
  • 2
  • 6
  • 19
  • it's an interesting take, but not quite what i had in mind. For one thing, i depends on `xdotool`, so it's not available across platforms. – amenthes Mar 17 '15 at 08:51