Open a URL in a certain browser tab/window
Asked Answered
I

2

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?

Ism answered 2/11, 2012 at 14:58 Comment(5)
Hi Elwood, did you ever find a solution to this? I have the exact same problem: #15117260Plotinus
Sipickles: Sorry, no. It seems it is just not possible. I was thinking about creating a local HTML file with <meta http-equiv="refresh" content="5" > in it and then overwriting this file on demand. But I did not try that yet and this approach probably has some downsides.Ism
I'm looking for the same thing (open in same tab) but preferably in Qt5. But I would also take a Qt4 solution.Jeremiah
Do any browsers even offer this feature?Mongo
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.Jeremiah
C
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.

Cupbearer answered 3/11, 2012 at 22:37 Comment(1)
Thanks phyatt. I'd rather not want to duplicate existing browser functionality by pulling in QtWebKit.Ism
S
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

Samantha answered 16/3, 2015 at 22:34 Comment(1)
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.Jeremiah

© 2022 - 2024 — McMap. All rights reserved.