Preface
First post. Very little HTML experience. Moderator: If this is the wrong forum, please move.
The problem I’m running into is less of an HTML/Javascript problem and more of a “what is written for one web browser doesn’t necessarily work (or work the same) on other web browsers.”
Requirement (The short version)
Instruct web browser to “go to” a specific HTML anchor tag from a 3rd party program. Solution must also work after the page has been rendered.
Requirement/The Problem (The long version)
I’m trying to develop a feature for an application I’ve written. I call the new feature “Smart Navigation”. Not necessarily the final name. The way it should work is fairly simple. Document 1 (local, dynamic, non-HTML) has pointers to HTML anchor labels in Document 2 (local, dynamic, HTML). When the user specifies use of a pointer in document 1, the web browser should “go to” the related anchor in Document 2.
When opening the web browser and rendering the HTML document for the first time, navigation is fairly straightforward. I can simply add “#{AnchorName}” to the end of document name. However, once the web browser is open, there is no way to update the browser’s command line without writing code for every web browser out there or restricting the user to Internet Explorer or a to custom window that uses a Web Browser Object or another custom web object.
So far, the solutions I’ve come up with work on some (most?) major web browsers, but not all. Unfortunately, the “problem” web browser(s) always includes at least one major browser. These solutions work by opening the web browser on the first request and refreshing (sending the F5 key) on subsequent requests.
Solution 1: HTML “Meta Refresh” tag. This solution embeds instructions to refresh the document to a specific anchor location when the document is originally rendered and when the document is refreshed (F5). The code is embedded in the header and looks something like this:
<html>
<head>
<meta http-equiv="refresh" content="0;url=#Line432">
</head>
...
This solution works flawlessly on all major web browsers except Opera (creates a perpetual reload loop) and Firefox and other Gecko derivatives (works fine for while but eventually goes into a reload loop).
Solution 2: Javascript “Location.Replace”. This solution is essentially the same as Solution 1 except that javascript is used. The code looks something like this:
<html>
<head>
<script language="javascript">
location.replace("#Line432")
</script>
</head>
...
This solution works flawless on some major web browsers but has problems with others. On Firefox and Gecko derivatives, it requires an additional refresh (F5) command to work. On Chrome and derivatives, it only works on the first call. i.e. F5 does nothing. On Opera, it works for a while and then it just stops working.
The feature is not a show stopper but it would be nice to figure out a way to “go to” a specific location in an HTML document without having to open a new window for each request or writing unique code for a few browsers.
If you have any ideas, let me know. Thanks.