redirect using a new window

1,550 views
Skip to first unread message

leone

unread,
Nov 24, 2010, 3:06:56 PM11/24/10
to web2py-users
Hi,
there is a way to redirect to a new page simulating <A ....,
target='new'> using URL()
or a controller function???
Thanks
leone

Michele Comitini

unread,
Nov 24, 2010, 3:47:05 PM11/24/10
to web...@googlegroups.com
do you mean like this?

{{=A('click me!', _href=URL(...), _target='new')}}

2010/11/24 leone <hand...@gmail.com>:

mdipierro

unread,
Nov 24, 2010, 5:19:15 PM11/24/10
to web2py-users
or

<a href="{{=URL(...)}}" target="new">click me</a>

On Nov 24, 2:47 pm, Michele Comitini <michele.comit...@gmail.com>
wrote:
> do you mean like this?
>
> {{=A('click me!', _href=URL(...), _target='new')}}
>
> 2010/11/24 leone <handja...@gmail.com>:

leone

unread,
Nov 25, 2010, 8:13:01 AM11/25/10
to web2py-users
Thanks for suggest, but I need something redirect(URL(..),
_target='new').
I fear that it doesn't exists, though web2py does anything.

mdipierro

unread,
Nov 25, 2010, 10:30:16 AM11/25/10
to web2py-users
I do not understand what you want to do.

leone

unread,
Nov 26, 2010, 12:42:42 PM11/26/10
to web2py-users
I need to redirect to a new page (for example as a new tab in
chrome....).

mr.freeze

unread,
Nov 26, 2010, 12:46:52 PM11/26/10
to web2py-users
Like so?:
A('Open in new window',_href=URL('...'),_target='_blank')

mr.freeze

unread,
Nov 26, 2010, 12:49:39 PM11/26/10
to web2py-users
Or do you mean use some javascript in the response to open a new
window?

leone

unread,
Nov 26, 2010, 2:16:05 PM11/26/10
to web2py-users
The first:
A('Open in new window',_href=URL('...'),_target='_blank')
.....but using redirection. There is a way?

mr.freeze

unread,
Nov 26, 2010, 2:32:39 PM11/26/10
to web2py-users
I don't think you would use redirect as you're not redirecting the
page but opening a new one. Something like this maybe?:

controller
----------
def index():
form = SQLFORM(...)
if form.accepts(request.vars,session):
response.new_window = URL(...)
return dict(form=form)

view
----
{{if response.new_window:}}
<script type="text/javascript">
jQuery(document).ready(function() {
window.open({{=response.new_window}});
});
</script>
{{pass}}

Wikus van de Merwe

unread,
Nov 26, 2010, 2:40:37 PM11/26/10
to web2py-users
If your talking about the HTTP redirect there is no such mechanism in
it. It's just a simple 303 response which informs your browser to
fetch the content of a page from a different URL. If you want to open
a new panel/window with URL_2 after visiting URL_1 that has to be done
with javascript.

Why do you want to do that anyway? Opening new panel/window is plain
evil (especially if done with javascript). This should be controlled
by the user, not the webapp developer who thinks he knows better what
the users want. Give a normal link and let the users decide how they
want to open it.

mdipierro

unread,
Nov 26, 2010, 2:41:32 PM11/26/10
to web2py-users
I still do not understand what you want to do. Perhaps you can explain
what problem are you trying to solve.

On Nov 26, 1:16 pm, leone <handja...@gmail.com> wrote:

mr.freeze

unread,
Nov 26, 2010, 2:43:25 PM11/26/10
to web2py-users
Whoops, forgot the quotes:
window.open('{{=response.new_window}}');

leone

unread,
Nov 26, 2010, 2:44:35 PM11/26/10
to web2py-users
Thanks.
I understand. I will use javascript with response var.

mr.freeze

unread,
Nov 26, 2010, 2:52:38 PM11/26/10
to web2py-users
I wouldn't rely on this behavior as almost all browsers will block it
by default. It is acceptable if it is for an intranet app where you
control the environment (i.e. can turn off the pop-up blocker for your
domain through group policy, etc).

Branko Vukelic

unread,
Nov 26, 2010, 7:38:38 PM11/26/10
to web...@googlegroups.com
Better solution would be to trigger a dialog after response. That will
work in most browsers in most environments.

--
Branko Vukelić

bg.b...@gmail.com
stu...@brankovukelic.com

Check out my blog: http://www.brankovukelic.com/
Check out my portfolio: http://www.flickr.com/photos/foxbunny/
Registered Linux user #438078 (http://counter.li.org/)
I hang out on identi.ca: http://identi.ca/foxbunny

Gimp Brushmakers Guild
http://bit.ly/gbg-group

Branko Vukelic

unread,
Nov 26, 2010, 7:39:09 PM11/26/10
to web...@googlegroups.com
I meant something like this: http://jqueryui.com/demos/dialog/

leone

unread,
Nov 27, 2010, 4:42:11 AM11/27/10
to web2py-users
Hi,
why doesn't run the simplest solution:
response.headers['Window-target']='_blank' (or _top,..or a window-name
of a page)
response.headers['Location']=url
raise HTTP(303,**response.headers)
????
> > bg.bra...@gmail.com
> > stu...@brankovukelic.com
>
> > Check out my blog:http://www.brankovukelic.com/
> > Check out my portfolio:http://www.flickr.com/photos/foxbunny/
> > Registered Linux user #438078 (http://counter.li.org/)
> > I hang out on identi.ca:http://identi.ca/foxbunny
>
> > Gimp Brushmakers Guild
> >http://bit.ly/gbg-group
>
> --
> Branko Vukelić
>
> bg.bra...@gmail.com

Michele Comitini

unread,
Nov 28, 2010, 4:13:23 PM11/28/10
to web...@googlegroups.com
AFAIK you cannot do it server side, there is no such header in
HTTP/1.1 standard, and a browsers do not support it

Use javascript or try to respond with a document with meta redirect:

<meta http-equiv="refresh" content="1;URL=http://blah.blah" target="_blank" />


2010/11/27 leone <hand...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages