It also explores the filtering behaviors of pop-up windows by common non-standard ie browsers and the corresponding countermeasures for using the pop-up window, in order to provide a general and better solution for using the pop-up window.
As Microsoft's latest tool for creating dynamic Web websites, ASP. NET has made great strides in changing the original Web programming methods compared with ASP and JSP. Its code and page Separation Technology (CodeBehind) and sophisticated Web server controls provide programmers with a Web server development method that is more in line with traditional programming. However, Web programming still has different characteristics from traditional programming, which determines ASP. NET programming must use some special skills to complete the program requirements. The pop-up window is exactly the representative of this type of programming method. A considerable number of programming books use silence or a phrase to bring the pop-up window, it seems that the pop-up window is a huge use of the world. This article will solve most of the issues in the pop-up window.
To improve the concurrency and throughput of Website access, ASP. NET uses client scripts to relieve the pressure on the server, just like other server scripts. ASP. NET does not support the pop-up window until now (Version 1.1). You must use JavaScript (or VBScript) to use the client pop-up window.
I. Warning window and using client scripts in CodeBehind
To display the simplest warning window in the browser, you can use the JavaScript statement:
Window. alert ([sMessage])
SMessage indicates the prompt information. Unfortunately, this pop-up window has only one "OK" button, which can only serve as a prompt. If you want to pop up a dialog box for asking when you delete a record, you need:
BConfirmed = window. confirm ([sMessage])
BConfirmed is the return value, and sMessage is the prompt information. The pop-up window has two options: "OK" or "discard". The returned value is placed in bConfirmed for the code to determine.
JavaScript and Codehind should be integrated to improve code reusability and readability. There are usually two ways to achieve this effect.
(1) Use the Response. Write method:
The Response. Write method has been supported in the ASP era. It can write code to the client, which is quite convenient and intuitive. The following code demonstrates how to use the Response. Write method to display a warning message.
Copy codeThe Code is as follows:
Private Sub btAlert_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles btAlert. Click
'Demonstrate the Response. Write method and alert window.
Response. Write ("")
End Sub
(2) Use the RegisterXXX Method
If you observe the HTML code generated by Response. Write, you will find that the code generated by the Response. Write method is written to the beginning of the HTML code, that is, before the tag. At this time, all HTML objects have not yet been generated. If you want to use and interact with the objects in HTML, the error "object not found" will occur. Therefore, we recommend that you use the RegisterXXX method, which is more in line with the CodeBehind method. RegisterXXX includes RegisterClientScriptBlock, RegisterStartupScript, and IsStartupScriptRegistered functions used for judgment.
RegisterStartupScript is prototype:
Copy codeThe Code is as follows:
Overridable Public Sub RegisterStartupScript (_
ByVal key As String ,_
ByVal script As String _
)
Key indicates the unique identifier of the script. script indicates the string of the script.
The prototype of RegisterClientScriptBlock is the same as that of RegisterStartupScript. The two functions differ in writing the script code included into different HTML files. RegisterClientScriptBlock sends a client script immediately after the start mark of the Page object element. RegisterStartupScript sends the script before the end mark of the Page object element. If your script has a statement that interacts with the Page Object (the doucument object) (as shown in the following example), we recommend that you use RegisterStartupScript, if you want to execute the client script as early as possible, you can use RegisterClientScriptBlock or Response. write.
To prevent repeated scripts on the page, the ReisterStartupScript/RegisterClientScriptBlock uses the key as the registered Key during script registration, and then the IsClientScriptBlockRegistered can be used in the program for judgment.
The following example uses RegisterClientScriptBlock to demonstrate how to use confirm.
Copy codeThe Code is as follows:
Private Sub btConfirm_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles btConfirm. Click
'Demonstrate the RegisterClientScriptBlock method and the confirm window
If (Not IsClientScriptBlockRegistered ("clientScript") Then
'Check whether the script has been added. If not, add it.
Dim strScript As String
StrScript = ""
'Register the script
RegisterClientScriptBlock ("clientScript", strScript)
'If you select "no", continue to the next step.
End If
End Sub
2. The specified page is displayed.
The prompt window is far from meeting our requirements. In the program, we often need to pop up the specified page. In this case, you can use the window. open Method of JavaScript. In combination with the previous RegisterClientSciptBlock method, we can implement the pop-up of the specified page.
The following code pops up a specified page:
Copy codeThe Code is as follows:
Private Sub btWinOpen_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles btWinOpen. Click
'Use window. open and registerStartupScript for simple demonstration.
If (Not IsClientScriptBlockRegistered ("OpenScript") Then
'Check whether the script has been added. If not, add it.
Dim strScript As String = ""
RegisterStartupScript ("OpenScript", strScript)
End If
End Sub
The program uses the Window. open Method to pop up a new page, which has only one parameter: the URL address of the new pop-up Window. The fact is that the window. open method has multiple parameters, but this is a simple example of objective cipt. We will not detail it here. If you have any questions, please query MSDN.
This program works normally in IE. However, if you are using browsers such as GoSurf, MyIE2, and NetCapter, unfortunately! You will not see the pop-up window. This is the pop-up window filtering question we will discuss.
Iii. Non-standard IE browser's discussion on pop-up window filtering Behavior
The proliferation of advertising windows has led many Internet users to abandon standard IE browsers and use software such as GoSurf, MyIE2, and NetCapter that uses the IE kernel to support multiple pages and automatically shield advertisements. It is said that Microsoft will also add the blocking advertisement Window Function in the forthcoming IE6 sp2. This is of course a good thing for most netizens. For programmers, the pop-up window is not essentially different from the general advertisement, such a window will also be banned by the pop-up window manager, and the result is of course not expected. Is there a standard way to make the window pop up normally? This requires us to understand the principle of blocking advertisements by browsers. Generally, the ad blocker uses the following three methods to filter advertisements:
(1) Blocking Based on window titles
The principle of this blocking method is to regularly check all the title of the IE window, and then compare it with the existing list (an array list maintained by the Program). If there is the same, close this window. Obviously, this method has many defects. It blocks all the pop-up windows, and is too hard to manage. It is rarely used in the program. However, the deformation method based on it is quite common. That is, the smart Filtering Technology Based on the title name of the window, which blocks ads based on whether the title of the pop-up window contains keywords, which makes a good exploration to improve the filtering effect.
(2) Blocking Based on the window class and Position
After analysis, we found that the class names of the normal window are IEFRAME and CabinetWClass, while the class names of the window for advertisement are CabinetWClass. Further analysis shows that the WorkerA class of the AD window and the rect of the Shell DocObject View class are displayed. the top value is the same. The WorkerA class of the normal IE window and rect of the Shell DocObject View class. the top values are different. Based on the above two points, you can write the advertisement killer program. In fact, I am skeptical about the versatility of this program. The analysis using Spy ++ found that in Windows2000 (the operating system used by the author), the classes of IE Windows are IEFrame. At the same time, because Win2000 is an operating system based on Unicode Code, there is no WorkerA class, and it is replaced by the WorkerW class. At the same time, the rect. top is not the same. Because I do not have a Windows XP operating system, I cannot perform further experiments on Windows XP.
(3) Blocking Based on ie com components
Both of the above methods treat IE Windows as a normal Windows window and make judgments. In fact, IE is a typical COM-based browser. All IE-based browsers package the shdocvw. dll file and then write the corresponding BHO code. Only in this way can we truly control ie browsers, rather than the itching of methods 1 and 2.
There is also a pop-up window blocking method based on the IE kernel. It can be intercepted before the pop-up window is opened. The principle is that every time IE opens a new window, the NewWindow event is triggered, and the OnNewWindow2 ([out] IDispatch *, [out] BOOL * bCancel) method is executed. Reload this method to determine whether a new window event occurs after the page has been downloaded. If yes, it indicates a normal pop-up window, and vice versa.
As a browser like Gosurf itself reloads the Shocvm. dll component, the use of the third method naturally becomes a matter of course. However, during use, you may find that ad filtering is not perfect, but the principle is basically the same.