title: Calling JavaScript function after a new aspx page is loaded on a new browser tab
body: <p>I have a form with a print button, when clicked, opens up a separate browser tab that displays a Sql Server Reporting Services report.  I am also passing two variables to this separate report page. </p>
  
  <pre><code>Protected Sub btnPrint_Click(sender As Object, e As EventArgs) Handles   btnPrint.Click
  
      Dim VID As Integer
      Dim SID As Integer
      Dim QueryString As String
      Dim dc As New VehicleDataContext(db.ConnectionString)
  
      Dim oReportPath = From rpt In dc.ReportLists _
                        Where rpt.ReportName = "Vehicle Service Record" _
                        Select rpt.ReportPath
  
      Dim sURL As String = "ReportViewer.aspx"
      Session.Add("ReportPath", oReportPath.First)
  
      VID = CInt(Session("VId"))
      SID = CInt(Session("SID"))
  
      QueryString = "ReportViewer.aspx?ID=" &amp; VID
      QueryString = QueryString &amp; "&amp;SID=" &amp; SID
  
      Response.Redirect(QueryString)
  </code></pre>
  
  <p>The report opens up without a problem, but the difficulty I am having is with the JavaScript. </p>
  
  <pre><code>&lt;script type = "text/javascript"&gt;
  
  function SetTarget() {
  
      document.forms[0].target = "_blank";
  }
  
  &lt;/script&gt;
  
  &lt;script type = "text/javascript"&gt;
  
   var ResetTarget = function () {
  
     document.forms[0].target = "_self";
  
          }
  &lt;/script&gt;
  </code></pre>
  
  <p>On the OnClientClick event for this button, I added the code to force the report to open in a new tab.  The second JavaScript function is to reset the application back to default behavior.  I placed a call to this code under the "Close" button, but I realized that clicking other buttons or links on the web page will keep opening up my form in new browser tabs, which I don't want. </p>
  
  <p>Is there a way of calling this ResetTarget script once the print button code has successfully completed so that other page events on this form don't keep opening up new windows?</p>
  
  <p>Thanks in advance.</p>