Project

General

Profile

Open new Browser Window to external website

Added by Gerald Brandt 7 months ago

Is there a way to force a new browser window to open pointing at an external website?

Basically, when the user presses a button, I want to run some code and then open a new browser window pointing to an external web site (on the same server).

Gerald


Replies (5)

RE: Open new Browser Window to external website - Added by Stefan Bn 7 months ago

Just use WLink in combination with setTarget:

WLink webLink = WLink("http://www.google.de");
webLink.setTarget(LinkTarget::NewWindow);

and assign this link to your WPushButton with

WPushButton::setLink

Best,
Stefan

RE: Open new Browser Window to external website - Added by Gerald Brandt 7 months ago

Thank you! It opens a new tab rather than a new window, but it's a great start.

Gerald

RE: Open new Browser Window to external website - Added by Gerald Brandt 7 months ago

Gerald Brandt wrote in RE: Open new Browser Window to external website:

Thank you! It opens a new tab rather than a new window, but it's a great start.

Gerald

So, this works, but is there a way I can execute some code before I open the link? I can obviously catch the onclicked, but I don't know how to launch the new window with the link.

Gerald

RE: Open new Browser Window to external website - Added by Stefan Bn 7 months ago

At least in Firefox it is a browser specific option/setting that defines whether a "new window" link will be opened in a new tab or a new window. Did you check that?

When I disable this option in my firefox, the LinkTarget::NewWindow will open a single new window (otherwise it opens a new tab, as you describe).

Otherwise you can experiment with some custom JavaScript code using WWidget::doJavaScript to force opening a new window.

https://www.w3schools.com/jsref/met_win_open.asp
https://developer.mozilla.org/en-US/docs/Web/API/Window/open

    (1-5/5)