Results 1 to 8 of 8

Thread: Javascript Open Window

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Javascript Open Window

    I am using Javascript to open a URL in a new window. It works fine except that the calling window refreshes and moves back to the top of the page.

    How do I make sure that the calling page stays in the same position?

  2. #2
    Lively Member
    Join Date
    Feb 2005
    Posts
    121

    Re: Javascript Open Window

    Hi,

    Can u please paste the code .

    It will help to understand.

    Regards
    -Sachien

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: Javascript Open Window

    VB Code:
    1. Private Sub JavaScriptOpenWindow(ByRef sURL As String, Optional ByRef sHeight As String = "768", Optional ByRef sWidth As String = "1024", Optional ByRef sToolbar As String = "0", _
    2.     Optional ByRef sScrollBars As String = "0", Optional ByRef sLocation As String = "0", Optional ByRef sStatusBar As String = "0", _
    3.     Optional ByRef sMenuBar As String = "0", Optional ByRef sResizable As String = "0", _
    4.     Optional ByRef sLeft As String = "0", Optional ByRef sRight As String = "0")
    5.         Dim sWindowRef As String = GenRandom()
    6.         Dim sJavaScript As String = "<script language=javascript>window.open('" & sURL & "','" & sWindowRef & "', 'toolbar=" & sToolbar & ",scrollbars=" & sScrollBars & ",location=" & sLocation & ",statusbar=" & sStatusBar & ",menubar=" & sMenuBar & ",resizable=" & sResizable & ",left=" & sLeft & ",right=" & sRight & ",width=" & sWidth & ",height=" & sHeight & "');</script>"
    7.         Response.Write(sJavaScript)
    8.         Response.Flush()
    9. End Sub

    The function GenRandom returns a random string which uniquely identifies the new window so that subsequent calls open another new window.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript Open Window

    What events on the page make you call a this subroutine? Is it being called from a link?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: Javascript Open Window

    I am calling it from a DataGrid1_ItemCommand routine in response to clicking on a link button column in the grid.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Javascript Open Window

    Perhaps you should be setting the navigateurl for your hyperlinks in the itemdatabound event, surely there is some logic to the sURL you generate? Simply make it call a predefined javascript function which already exists in your ASPX code instead of going through this hassle.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: Javascript Open Window

    If I can find a way around this with my current code, it would be better because it works exactly the way I want it to except for the refresh problem.

    Is there some way that I can create an anchor at the row on the grid that the user clicked on to open the new window? I could store the row number in either a hidden label or in a session variable and have a button at the top of the page called "Go To Last Position" which when clicked on would go the row that was clicked previously. This would do the job for me.

  8. #8
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: Javascript Open Window

    Great Code Robertx , you have gained my rating for this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width