Project

General

Profile

Open a new tab

Added by Marcelo Antunes over 4 years ago

I have a button, called export, wich when clicked it generates a file and open it in another browser tab.

I already have the link to the file, but how i open the file in another browser tab?

Regards


Replies (8)

RE: Open a new tab - Added by Harm ​ about 4 years ago

I think this is what you're looking for:

https://www.webtoolkit.eu/widgets/navigation/anchor

RE: Open a new tab - Added by Marcelo Antunes about 4 years ago

Now i have a pushbutton, and inside the slot conected to signal clicked, i generate the file.

If i replace the pushbutton by an anchor, i have tho change the destination of anchor, inside the clicked slot.

I change it inside the slot, but it just is applied the next time i click on the anchor, not the current time.

regards

RE: Open a new tab - Added by Harm ​ about 4 years ago

Ah, we've had this problem a few times too.

We've worked around this in our project in 2 ways:

- We either do the actual exporting earlier, and make the exportbutton have the downloadlink (not always possible),

  • or we make the export-function create a "Your file is ready for download"-dialog, with a downloadbutton in it.

I don't know if there's other ways.

RE: Open a new tab - Added by Roel Standaert about 4 years ago

What I most often do is create a WResource that generates the file in handleRequest() when requested.

RE: Open a new tab - Added by Roel Standaert about 4 years ago

There's an example of such a WResource in the widget gallery: https://www.webtoolkit.eu/widgets/media/resources

Of course, your handleRequest() function will probably be more elaborate. In any case, the contents of the file need to be sent to response.out().

RE: Open a new tab - Added by Marcelo Antunes about 4 years ago

Roel Standaert, the problem isn't generate the file, is show it.

I generate the file inside the slot connected with the export button.

The behavior that i want for the export button is generate the file and after download/open it in a new tab.

I already have the code to generate the file, the problem is download it.

regards

RE: Open a new tab - Added by Roel Standaert about 4 years ago

Yes, but the way that that can be accomplished, is by not generating the file in a slot connected to the button, but rather by generating the file in the handleRequest() function. Then, you don't put a clicked() handler on the button. Instead you set a link to that resource on that button.

Is there some reason why you can't do that? Because the file maybe takes a long time to generate maybe?

RE: Open a new tab - Added by Marcelo Antunes about 4 years ago

I solved the question, when it finishes generate the file, it opens a dialog with a link to the file

regards

    (1-8/8)