Attributes.Add("onclick", ... & window.Focus()

G

GD

I have an ImageButton in a Repeater, and in the Repeater's
OnItemDataBound event, I'd like to add some code that will let the
ImageButton open a URL in a new window.

This is what I have in my Repeater's OnItemDataBound event:

ImageButton oImageButton =
((ImageButton)e.Item.FindControl("ibtnNewWindow"));
string sUrl = "http://www.cnn.com"; // Just as an example
string sWindow = string.Concat(@"javascript:window.open(',", sUrl, "',
'_blank', 'toolbars=no,status=no,menubar=no,location=no')");
oImageButton.Attributes.Add("onclick", sWindow);

The works great, except that the new window doesn't retain focus when
it's opened.

How can I use window.Focus() to ensure that the new window receives
focus?

Thanks
 
G

Guest

Try

var newWindow = window.open(sUrl, , '_blank',
'toolbars=no,status=no,menubar=no,location=no');
newWindow.focus();

HTH

Elton Wang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top