Reputation: 31
I have a website that upon a person going to it, it checks a timestamp on the database. If the timestamp is over 4 hours old then it opens a popup window that runs a database import/update sub that updates the database. Then closes itself out afterward.
The reasoning for doing it this way is it allows the person browsing to continue about their business while a separate window takes care of the update.
Right now this popup appears as the focus. Is there a way to make the popup load behind the current browser window as to not intrude the users navigation?
Here is the page_load
sub of the main window.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim connStr As String = ConfigurationManager.ConnectionStrings("SNA_TRT").ConnectionString
Dim sqlConn As SqlConnection
sqlConn = New SqlConnection(connStr)
sqlConn.Open()
Dim strSQL As String = "SELECT TOP 1 [ID], [LASTREFRESH], [BYWHO] FROM [TRT_db_timer] ORDER BY [ID] Desc "
Dim cmd As New SqlCommand(strSQL, sqlConn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
Dim lastupdate As DateTime
Dim currenttime As DateTime = Now()
While dr.Read()
lastupdate = Convert.ToDateTime(dr(ClearNullDs("LASTREFRESH")))
End While
dr.Close()
sqlConn.Close()
Dim ts As TimeSpan = currenttime.Subtract(lastupdate)
Dim dbspan As String = ts.TotalMinutes.ToString()
Dim dsinceup As Integer = ts.Days.ToString + 1
'MsgBox(lastupdate)
'MsgBox(currenttime)
'MsgBox(dbspan)
If dbspan > 240 Then
bodytag.Attributes.Add("onload", "window.open('/trt/admin/importnotice.aspx?DAYS=" & dsinceup & "',null,'height=150, width=350,status=yes, resizable=no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
End If
End If
End Sub
Upvotes: 0
Views: 1977
Reputation: 89322
There are definitely better way to do this (like ajax).
But to answer your question:
function loadpopunder(){
var popunder=window.open(/* popup window parameters */);
popunder.blur();
window.focus(); // focuses the main window.
}
Upvotes: 3
Reputation: 1263
If you want the update to happen when the user arrives at the site, use AJAX or a hidden iframe. If you want the update to happen every X hours no matter if the user visits the site, use a CRON job. Popping up a window to do this will aggravate the user.
Upvotes: 1