This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
Onstop, Connecting to SQL with ASP, Hiding Images, Passing Values from a Control |
Robert Hess |
Q How can I detect if a user clicks the browser's Stop button while viewing my Web page?
A Starting with Microsoft® Internet Explorer 5.0, your client-side code can trap the onstop event. This will let you know when the user clicks the Stop button, hits the Escape key, or when the page is being unloaded.
It is important to remember that onstop will also be triggered when the page is unloaded through normal navigation away from the page, so you want to make sure that whatever processing you do takes this into account. The easiest way to do this is to also watch the onbeforeunload event. During normal navigation off a page, the onbeforeunload event will be triggered before the onstop event, so you could easily set a flag or change the function to handle onstop properly.
Q I am trying to use ASP to connect to a SQL Serverâ„¢ database, but the DBMS and Web server are separated by a firewall. I am using a SQL OLE DB driver and I believe that SQL Server is listening on port 1433, but I can't open a connection. Should I be able to just change my connection string from:
to this:
If not, how do I tell the OLE DB driver which port to use for communication?
A I checked with a local expert on server connectivity issues. He says that port 1433 is the standard port for SQL TCP/IP connectivity, and it's the port that SQL Server uses by default. So it's likely that the firewall in front of the machine running SQL Server doesn't have this port open. This is the very first thing you should check. Q I have an absolutely positioned <DIV> block that is initially hidden in my HTML page. When I expand it, I can get it to overlay all elements except a <SELECT> element. Is there anything special about the z-index of <SELECT>?
How can I use the control inside the form to send the value from the control to other.asp? I would like to use this ASP code:
A An ActiveX control can't just simply be included within the processing of a form submit request, but there are ways to allow the values entered in the control (or Java-language applet, or whatever) to be passed along to the server and be processed as though they came from a standard form control.Basically, all you need to do is intercept the submit event and copy the appropriate information from your ActiveX control into a hidden form element (see Figure 2). Q How do I disable the Save Picture As option that pops up when a user right-clicks on an image displayed in their browser? A It sounds like you want something to protect the images you display on your Web site. The way browsers simply allow free access to all of your images is just a little scary. And I expect it isn't just the Save Picture As behavior, but also Copy, and Set as Wallpaper that you'd like to limit. When you get right down to it, you probably don't want that context menu popping up at all.
and the user will never see a context menu for that item.For those who aren't using Internet Explorer 5.0, you can do something tricky with Cascading Style Sheets (CSS):
Here I'm using the <IMG> tag to display a transparent GIF image of the same height and width as the real image. I then set the CSS background of the image to display the actual picture. This will work in Internet Explorer 4.0.Unfortunately, this trick doesn't appear to work in Navigator, but the following variation will:
This does basically the same thingâ€"it layers the transparent image on top of the one the user wants to copyâ€"but this time by setting the real GIF as the background of the <DIV> rather than the background of the image.So what if the user has a version of Internet Explorer or Navigator that supports none of the tricks I just mentioned? I guess you're out of luck. And remember, all the user has to do is view the source of your page in order to find out the URL of the image, and navigate to that file directly. In that case, you won't have any control over access to your images. Q I have written an app in Visual C++® that will play back a video file (mpg, asf, avi, and so on). One feature I added is the ability to start at a given time using a command-line argument in the form of filename.ext?hh:mm:ss for hours, minutes and seconds, respectively. I have changed the registry on my PC to make my app the default viewer, setting the default key for HKEY_CLASSES_ROOT\mpegfile\Shell\Open to c:\Path\To\My\App.exe "%L". The problem is that clicking on one of the files will open my viewer, but if I create a Web page with an anchor set to <a href="video.ext?00:00:05">, the only thing passed to the command line is the path to the file and the file name, not the ?00:00:05 argument. Note that this is written to play videos on the hard drive, not the Internet. So, how do I pass a command line via a Web page link? A Technically, there isn't any reason the data following the file name in an href couldn't be passed on to an executable as the command line, but in reality this doesn't happen. This is most likely a security feature. Consider for example:
Perhaps very few folks would actually press "Y" to format their hard drive, but it might catch some folks, so you get the idea.When an href is used as a link to an executable, essentially everything following the "?" is removed as the browser determines which file it should download and run. But that doesn't mean you're down for the count. The issue isn't how you encode a command line into an href, but rather how you control the functionality of an application that is executed from a Web page. This might sound like the same thing, but it is a little different. Perhaps the easiest solution is to implement your application as an ActiveX control. This would allow you to simply put an <OBJECT> tag in your page that identified the application to execute, then <PARAM> tags define how this application is to be initialized. Thus, your application could be launched as:
Of course, there are issues with this solution. For instance, it may not be feasible to turn your particular application into an ActiveX control. In this case an alternative would be to write a new ActiveX control that is essentially just a launcher app, which would be invoked like this:
If you're not ready to deal with ActiveX and COM, an even simpler (but more roundabout) solution would be to create an application that simply reads in values from a file and takes specific action on them. For example, if you associate this new application with the .loader file extension, then the anchor on your page might look like:
And the contents of videoplayback.loader might look like:
All your app would need to do is read in the first line, use that as the application name to execute, and then read the second line and use that as the command line to pass to the application. You would then use these as parameters for the CreateProcess call.Q I am trying to form an XML schema in both Microsoft XML Schema format and Document Type Definition (DTD) format. My requirements are that the tags in a particular element can be in any order, but they can appear only once. This works using XML Schema (see Figure 3), but not using DTD. Can you tell me if it is possible in DTD format? A The minOccurs and maxOccurs of the XML Schema format makes this fairly easy and straightforward. According to the DTD folks, it appears that while it is possible to represent this in DTD, it gets a bit verbose. Here is essentially what you need to do:
Got a question? Send questions and comments to webqa@microsoft.com |
Robert Hess is currently the host of "The MSDN® Show" (https://msdn.microsoft.com/theshow) and is a regular contributor to various areas of MSDN. |
From the November 2000 issue of MSDN Magazine.