Open new window using Javascript or Hyperlink

G

Guest

I am trying to open a new window in two ways
1 - adding javascript to the onclick attribute of an Image button to open a
pdf document in a new window as
javascrit:window.open('MyPage.aspx',status=1,location=1,resizable=yes,scrollbars=yes)

2 - I am using a HyperLink and using the NagigateUrl property to open a pdf
in a new window with the targer set as "_Blank"

The trouble I am having is trying to keep the focus on the new window.
Sometimes it opens with the focus then almost immediately loses focus. Some
time it opens but does not have focus . It is not minimized just loses focus.
THe behavoir is inconsistent

How can i prevent this
Do i use the respone object
With Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.Buffer = True
.WriteFile(strFileName)
.Flush()
.Close()
End With

Any ideas or suggetsions will be appreciated.
Jawahar
 
W

William F. Robertson, Jr.

window.open returns a reference to the new window. Could you focus it that
way?

javascript: newWindow = window.open( '...' ); newWindow.focus();

bill
 
J

James Doughty

Do you have smart navigation turned on? This caused me problems and I
have to rewrite a pieve of the smartnav script.
 
Joined
Nov 19, 2008
Messages
1
Reaction score
0
William F. Robertson said:
javascript: newWindow = window.open( '...' ); newWindow.focus();


I have to do a modification for this to work, because I still losing focus:

Code:
[INDENT]
<script language="javascript" type="text/javascript">
[INDENT]
var newWindow;

function newWindowFocus()
{
[INDENT]newWindow = window.open( '...' );
setTimeout('newWindow.focus();', 50);[/INDENT]
}[/INDENT]

</script>[/INDENT]



An then call the funcion in the link/image:


Code:
[INDENT]javascript: newWindowFocus();[/INDENT]





  • You have to do a Function because the variable newWindow must
    be global
  • The function "setTimeout" inserts a delay before set the focus, that allow that others focus() that mae be causing the problem execute first.

8)
 
Last edited:

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,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top