Loading and Rendering Files VB Help

The code of the IITMLEditor application has two more interesting procedures. The Save command on the File menu stores the contents of the RichTextBox control (thE HTML source code) to a disk file with the Savef’ile method of the RichTextBox control. The HfMl, source code is saved as  text with the following procedure:

The Open command is a bit more involved, as it must handle various types of file other than IITML files. When an H1ML file is opened, its source code must app.early in the editor’s box, and the document must be rendered on the WebBrowser control If the document is an image (a JPG or GIF file), it must be rendered in ,the Web-Browser control, but the file’s contents must ~t appear in the editor. If it’s a sound,  it must be played back, but the file’s contents must not be displayed. The code of the Open command is:

Private Sub FileOpen_Click()
On Error Resume Next

If the user selects an HTML or text file in the File Open dialog box, it’s displayed in the editor, and the program attempts to render it on the WepBrowser control. If not, the WebBrowser control is navigated to this file. If it’s a file that the browser can handle, it does so. If not, no error message is generated. This is a feature of browsers: when they run into information they can’t handle, they process as much information as they can or ignore it altogether. But they won’t generate any error messages. The error handler was included in case something goes wrong with the VBcode.

The History Object

The History object provides methods for navigating through the browser’s history. In other words, it lets you access the functionality of the browser’s navigation buttons from within your code.

The Methods of the History Object

The History object of the Scripting Model maintains the list of sites already visited, and you can access them through the History object’s methods, which are described next. The History object doesn’t have its own properties or events. Back n This method moves back in the history list by n steps, as if the user has clicked the browser’s Back button n times. To move to the most recently visited URL, use the following statement: .

Call Window.History.back(O)

Or simply use this statement:

Call Window.History.back

Forward n This method moves forward in the history list by n steps, as if the user has clicked the browser’s Forward button u times.

Go n This method moves to the nth item in the history Ilst. The fallowing statement takes you to the first URL in the list:

Window.History.go 1

The Navigator Object

The Navigator object returns infonnatio •about the browser, One of the major problems you will face as a Web author is that the two major browsers (Netscape Navigator and Microsoft Internet Explorer) are not totally compatible. Each supports a few unique features that the other doesn’t. The truth is, both Netscape and Miaoso try to catch up with each other instead of attempting to establish new standards. Developing pages that will work on both browsers is not a trivial task.especially be those who design active pages. Even if you Can’t design a page that can be rendered on both browsers, you can at least have two sets of pages, one for each browser. and display the appropriate pages. Even for this crude technique to work, you must figure out from within a saipt which browser is opening the page , The properties of the Navigator object are read-only, ‘and they return information about the browser in which the document is viewed.

AppCodeName This property returns the code name of the application. Internet Exp~orer returns “Mozilla.”

AppName Thisproperty returns the name of the application. Internet Explorer returns ”Microsoft Internet Explorer.

AppVerslon Thismethod returns the version of the application. Internet Explorer 4 under Wmdows 95 returns “4.0 (compatible; MSIE 4.01; Wmdows 95.” Future versions of Internet Explorer.and Wmdows 98 may return a slightly different string. ‘

UserAgent ,This method returns the user agent of ~ application. Internet Explorer 4 returns “Mozilla/4.0 (compatible; MSIE 4.01; Wmdows 95).

Suppose you have prepared an HI’ML page that can be viewed with any browser ‘ (in other words, a generic page), and you have prepared a more advanced version of the same page that includes features supported only by Internet Explorer 4. You can easily detect which browser is running atthe client’s side, and you can displaythe advanced page if the browser happens to be Internet Explorer 4 and display the generic HIML page, for all other browsers.

To find out the values of the various properties of the Navigator object, run the HI’MLEditor applicatioi) (discussed earlier in this chapter), and create a small saipt like the following One:

in which propName is the actual name of a property of the Navigator object. Thenrender the document, and the property’s value w,ill appear in the  loweL pane of the IflMLEditor window.

Posted on November 6, 2015 in Visual Basic and the Web

Share the Story

Back to Top
Share This