Create a pop-up "Daily prompt" window

Source: Internet
Author: User
Tags date dsn readline
* This routine will use application objects, databases, JavaScript, and file operations.

First, let's make a list of what this routine will involve:


1 We will create a pop-up window to display a "daily hint";
2 hint will present different content every day;
3 The content of the hint is kept in the database and received the request instruction from the Internet;
4 Prompts the content to update conveniently, also may add the new content at any time;
5 provides a means to list all hints.

Below, we will cover the details of the issue. We only discuss some of them, and other information will be provided by the actual resulting document (what does that mean?). Spider Jing also don't quite understand, treat us to look back and see again.

I need to know which hint is currently displayed. In order to transmit the number of the current hint, we need to use the application. Also, to be aware of this when you update the prompts, we'll archive the displayed hint number and save it on disk. This is done to prevent data loss in the event of a server reboot, power outage, sabotage by counter-revolutionary elements, illegal organization of black-red sites, etc. We use TIPSTORE.DAT as data archive file. It contains two lines, one line is the number of the hint, and one row is the data.

Because these values are kept in application, we can take them out of the TIPSTORE.DAT when we run the daily prompts. The best way to do this work is to use Global.asa in Application_OnStart. GLOBAL. The ASA file can take these values out. Please raise your hand if you know how to translate the following sentence. This was done, courtesy of the FileSystemObject and its support through the Textstreamobject methods: (OK, put your hands down!) Now that you know it, I won't explain it.


Phypth = Server.MapPath ("/tipstore.dat")
Set Filsys = CreateObject ("Scripting.FileSystemObject")
Set tipfil = Filsys.opentextfile (phypth, 1)
Application ("Curtip") = Tipfil.readline
Application ("SYMDT") = CDate (Tipfil.readline)
Tipfil.close
Set Tipfil = Nothing
Set Filsys = Nothing

We select Server.MapPath to indicate the physical address of the file. This allows the code used to process DAT files to be used for multiple sites without modification. Filsys created as Textstreamobject for Filesystemobject,tipfil. We can then read the data from this file and then close it when it's done.

Next, let's take a look at this update prompt page. This is also the page where we give the user the option to prompt. I might suggest that you put it on your homepage, but it can be put anywhere. Let's take a look at the contents of this file named home.asp:

<%

' Tip of the day processing
If Application ("Symdt") < Date Then
Application.Lock
Curtip = Application ("Curtip") + 1
SYMDT = Date
Application ("Curtip") = Curtip
Application ("SYMDT") = Symdt
Application.UnLock

Phypth = Server.MapPath ("/tipstore.dat")
Set Filsys = CreateObject ("Scripting.FileSystemObject")
Set tipfil = Filsys.createtextfile (Phypth, True)
Tipfil.writeline (Curtip)
Tipfil.writeline (CSTR (SYMDT))
Tipfil.close
Set Tipfil = Nothing
Set Filsys = Nothing
End If

%> ...
Until finally, we check to see if the current prompt is newer than the previous prompt. If the first user visited the page that caused the new data, it would be easy for us to handle the change. (understand?) Anyway, Spider-Jing is a monk. I found that the most headache of translation technical data is not technical content, but how to understand the author's meaning. Vulgar life is dull, talents, intuition is not very keen, only to leave the content of the net friends. Please see the English version of the original. If we lock the application, we will not get repeated changes. Select the number of the next prompt and deposit the current number in the data for tomorrow. For many of these reasons, it is necessary to deposit the results of the processing into the document. (Unless you're a mud player or a love affair with a network lover.) Can "hours a day, 7 days a week" to open the machine)

To produce a pop-up browser window, we have to use JavaScript to do it. The following function can complete this function.

function displaypopup (URL, height, width) {

Properties = "toolbar=0,location=0,scrollbars=1,height=" + = height;
Properties = Properties + ", width=" + width;
Properties = Properties + ", left=0,top=0";
popuphandle = open (URL, "Tipwindow", properties);

}
As you can see, we could display any URL in this pop-up window. We can also control the height and width of the window. For different browsers, the results from the code are not the same, so you need to test in IE and Netscape. I have preset some parameters to adjust the window we want to generate.

JavaScript to think we create this window.
Url:

<a href= "Javascript:displaypopup (' popup.asp ', 300,300)" >

The ' javascript: ' protocol tells the browser that the code is interpreted by the JavaScript engine and is not related to the Web server. This allows us to have the popup.asp as an address when the browser processes the function. Window size is 300x300 pixel.

Maybe it's time for popup.asp to be on the show.

<%

TIPNBR = Application ("Curtip")

Set Rsttip = CreateObject ("ADODB. Recordset ")
Rsttip.open "SELECT * from Tip WHERE tip=" & Tipnbr, _
"Dsn=tipdata"
%>
We created the Rsttip as a recordset to access the database, which is registered as a System DSN (Systems DSN) (the registration method is not much said, done in Control Panel). The name of the DSN is ' Tipdata '. In the record, we focus on the prompt number that is stored in the application.

We want to display the relevant information from the record.


... <% = Rsttip ("Tiptitle")%> ...
In this way, we write the domain ' Tiptitle ' from the current record and return it to the browser. When we have finished the display, we will close it and release the object.


... <%
Rsttip.close
Set Rsttip = Nothing
%> ...
You will find another two ASP files: resettips.asp The prompt number back to the beginning of the list; tiplist.asp displays all prompts in the format you specify.

I wish you a happy programming!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.