Open a new page in the browser from redirect or URL

53 views
Skip to first unread message

João Matos

unread,
Mar 8, 2019, 2:03:39 PM3/8/19
to web...@googlegroups.com
Hello,

I have this function

def check_only_one_selection(ids, destination):
   
# type: (List[int], str) -> None
   
"""Check only one selection in grid.

    :param ids: List of Ids.
    :param destination: Destination page if one selection was made.
    """

   
if len(ids) > 1:
        session
.flash = T('Select only one record.')
   
else:
        redirect
(URL(destination, args=[ids[0]])



and would like it to open it's view on another web page (not the same from where it was called).
Something similar to this
<a target="_blank">

but without using A.

Is it possible?

Thanks.

Leonel Câmara

unread,
Mar 8, 2019, 2:39:06 PM3/8/19
to web2py-users
It's sort of possible using response.js = "window.open(url, '_blank')" however any modern browser will consider this a popup and block it because it's a window.open that's not coming as a direct result of a click, you can then move a step forward fighting with the user's browser preferences and instead of using window.open you send javascript that creates an A element and clicks it, or even a form that submits to another page. 
 
Don't do this, it won't work reliably. Depending on what you're trying to do a good alternative can be to use a modal, or putting a _target="_blank" in your form so it submits to a new window.

João Matos

unread,
Mar 8, 2019, 3:07:55 PM3/8/19
to web2py-users
The problem is that my origin page has a grid with extra buttons, using the selectable option.
And that option does not allow using _target or anything similar. It can only call a function (which is the function on the 1st message).
That function checks if there is only 1 record selected in the grid and if so calls the button action (add, edit, ...)
What I would like is for this action to open a new page.

Do you see some solution?

icodk

unread,
Mar 8, 2019, 6:08:50 PM3/8/19
to web2py-users
I would do it in javascript in the view and simulate radio buttons, which means that every time the user is selecting a checkbox the script will clear the former selected checkbox. This way you don't have to deal with informing the user, about multiple selections.

João Matos

unread,
Mar 8, 2019, 6:14:16 PM3/8/19
to web2py-users
The grid's checkboxes (and their multiple selection) are not the problem.
The problem is that my origin page has a grid with extra buttons, using the selectable option. And I wanted one of the buttons (from the selectable option) to open a view in another browser page.
Can I control the buttons from the grid's selectable option from Javascript?

icodk

unread,
Mar 8, 2019, 6:14:37 PM3/8/19
to web2py-users
My be it is an idea for improving the grid by add (yet another)  option   to have radio buttons instead of checkboxes
Reply all
Reply to author
Forward
0 new messages