Omnis Technical Note TNWE0003
How to redirect an HTML page depending on the browser and the platform
For Omnis Studio
By Rudolf Bargholz
Due to its publication date, this technote contains information which may no longer be accurate or applicable on one or more of the platforms it refers to. Please refer to the index page which may contain updated information.
The following tech note will be useful for those who use the Omnis Web Client and have to redirect their Web Form page depending on the browser the client is using.
Problem
When using the Omnis Web
Client, you have to embed a reference to the web client object code in
an HTML page. As the object code for Netscape and Internet Explorer object
differs, one is normally forced to create two HTML pages for one web form,
one that uses the Netscape object code format and one that uses the format
for Internet Explorer. To complicate matters, the Internet Explorer on
the Mac needs to use the Netscape object code format. What would be ideal
is, if one opens an HTML page in the browser, the browser recognizes what
browser the client is using, Netscape or Internet Explorer, what platform
the browser is running on, and then redirects the window's HTML location
to the required HTML page. Another issue is to open the browser window
with no toolbar or menu items visible
Solution
For the browser to be able to recognise the browser type and the platform,
one has to embed JavaScript in one's HTML page:
<HTML> |
A couple of points regarding the example code
1) In a JavaScript section, a line is commented out using a preceding
"//".
If one removes the preceding "//", e.g. in the line
// document.location(BrowserPlatformURL);
to
document.location(BrowserPlatformURL);
one effectively removes the comment and the line will be executed.
2) For debug purposes I have used the following code in the BODY section
of the HTML:
document.write("<p>");
document.write(navigator.appName);
document.write("<p>");
document.write(navigator.appVersion);
document.write("<p>"); document.write(getBrowser());
document.write("<p>");
document.write(getPlatform());
All these lines of code do is write text to the browser. The text written
is determined by calling JavaScript functions embedded in the HTML, e.g.
"getBrowser()", or by referencing JavaScript variables, e.g. "navigator.appName".
These lines can be deleted from the HTML text when deploying the code.
When deploying the code, one has to uncomment the line BODY section
// document.location(BrowserPlatformURL);
to
document.location(BrowserPlatformURL);
The JavaScript function "document.location(BrowserPlatformURL);" will
open the URL stored in the variable "BrowserPlatformURL".
3) The variable "BrowserPlatformURL" is filled with the following line
var BrowserPlatformURL = getPage();
where "getPage()" is a JavaScript function that returns the correct URL
depending on the browser and the platform.
4) The JavaScript function "getPage()" has four variables defined
var BrowserName = getBrowser();
var PlatformName = getPlatform();
var NetscapeURL = "netscape.htm"; // enter your Netscape URL here
var ExplorerURL = "explorer.htm"; // enter your IE URL here
The variable "BrowserName" is filled by calling a function called "getBrowser()".
This function will return "IE" for the Internet Explorer or "NS" for Netscape.
The variable "PlatformName " is filled by calling a function called "getPlatform()".
This function will return "M" for the Mac platform, "W" for the Windows
platform or "L" for Linux platform.
The variables "NetscapeURL" and "ExplorerURL" can be used to store the
URL of the respective Netscape or Internet Explorer Omnis Web Client HTML
pages, e.g.
var NetscapeURL = "http://www.mytest.com/IE.htm"; // enter your
Netscape URL here
var ExplorerURL = "http://www.mytest.com/NS.htm"; // enter your
IE URL here
The function "getPage()" will either return
"http://www.mytest.com/IE.htm" or
"http://www.mytest.com/NS.htm" or
the text "ERROR" if an unsupported browser is used or the platform is
not supported.
If a URL is returned, the function
document.location(BrowserPlatformURL);
will open that URL in the current browser.
5) If one does not want the new browser window that opens to have a menu
bar or a toolbar, one can use the JavaScript function
window.open(address, "NewWindow", option )
a) 'address'is the URL to be opened
b) ' "NewWindow" ' tells the command to open a new window
c) 'option' is a list of parameters that are to be passed to the to be
opened window, telling it what it is to display and what not to
The JavaScript 'window.open(address, "NewWindow", option )' can be found
in the HTML above in the JavaScript function
function customOpen()
{ ....
} The function can be called via an HREF, e.g. ...
<BODY>
...
<A href="javascript:customOpen()"> Press here to open the correct
web page </A>
...
</BODY>
For more information on JavaScript see the following links:
www.javascript.com
www.searchscript.com
www.easyjavascript.com/javascript.html
www.websitesetup.org