Programming Websites


1. How do I write a program that calls up a Website?

The following program shows how to display a local HTML file in the default web browser. The same principle can be used with actual websites which are simply HTML files stored remotely on the internet. This example assumes a file "test.htm" exists in the same folder containing the program when it runs:

  // Web2.cls
  Ubercode 1 Class Web2

  public function main()
    BrowserPath : string[*]
    BrowserPath <- RegGetBrowser()
    if Filesize(BrowserPath) > 0 then
      call Exec(BrowserPath, Dirstart()+"test.htm", EXEC_NOWAIT+SW_SHOWNORMAL)
      call Msgbox("Default browser", "Cannot find default web browser.")
    end if
  end function

  end class

The program starts by getting the name of the default web browser. Then it runs the browser EXE file (usually Internet Explorer) and uses it to load "test.htm". The call to Exec continues running after the web page is shown. This technique can be used as the basis for a program that shows HTML files.

If you wanted to modify the example to show a remote website (ie an HTML file across the internet) then change the local HTML filename from Dirstart()+"test.htm" to (for example). The example program used a local file test.html simply to make sure the example works on a computer without an internet connection.

2. How do I run an EXE file from a web browser?

To do this, create a web page which has links to the relevant EXE file (the EXE file should be stored locally). Create the following web page:

  <title>Web page that runs EXE files</title>
  <h1>Web page that runs EXE files</h1>
  <p>Click <a href="file:///C:/windows/notepad.exe" class="navbar">here</a>
  to run notepad.exe (Windows XP, ME, 98, 95)</p>
  <p>Click <a href="file:///C:/winnt/notepad.exe" class="navbar">here</a>
  to run notepad.exe (Windows 2000, NT)</p>

Cut and paste the text shown, and save it as a file "test.html". The file must have the extension ".htm" or ".html". After saving the file, use Windows Explorer to locate the file and run it by double clicking it. You will then see a web browser window with two links, one to run "notepad.exe" under Windows XP / ME / 98 / 95, and a second link to run "notepad.exe" under other versions of Windows. The browser window should look like this:

Programming Web Sites - Web page to run EXE files

Click the link that matches your version of Windows. When you click the link, Windows may pop up a warning window to confirm whether it is OK to run the EXE file. It's safe to allow the EXE file to run, since "notepad.exe" is part of Windows. It is also safe to run other EXE files on your computer if you created them. To run Ubercode EXE files, write and compile your program, then change the web page and insert the name of the program's EXE file instead of "notepad.exe". When you next view the local web page, the links will run your program.

You can use this technique to create programs consisting of a mixture of local web pages and local EXE files. Create the web pages with the text and graphics you want, and add links from the web page HTML files to the programs you want to run. It is safe to run EXE files that are part of Windows, and EXE files produced from programs you have written. But it is only safe to run EXE files downloaded from the internet if you trust the source - this is why the browser pops up the warning message when you run the file.