472,992 Members | 3,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,992 software developers and data experts.

Compaibility issue: window.location mismatch with browser locationbar

I already understand that one cannot disable a browser's
forward and back functions. This is a situation where I
have code working in Mozilla V1.6 and would like something
similar for Opera and IE.

I link within a page and display individual divisions of
that page, manipulating their visibility and display styles
with an onClick function. As long as I explicitly click a
link to progress, it works with browsers I've tried.

If I click the browser's back button I see the content of
the browser's location bar change as I expect. But I
need to set the visibility and display styles for the
corresponding division. In Netscape/Mozilla I have a little
function enabled by setInterval(). It looks to see if
window.location.hash matches the division which is visible
and modifies styles accordingly.

Under IE window.location.hash seems to be "stuck" at the
most "forward" link. Under Opera I can get only the URL
without the hash; it claims that the hash property is
undefined or empty. I've tried document.location and
document.URL with the same results.

Since there's no page load or unload involved, there's no
event generated; I could kludge some history of my own to
traverse.

Am I looking in the right place to get the hash info? Is
there some direct access to read the location bar?

Is there another approach to the problem, other than breaking
up the page so that I force a load or unload?

Thanks for any help.
Jul 23 '05 #1
5 7454
spam_me_ not wrote:
I already understand that one cannot disable a browser's
forward and back functions. This is a situation where I
have code working in Mozilla V1.6 and would like something
similar for Opera and IE.

I link within a page and display individual divisions of
that page, manipulating their visibility and display styles
with an onClick function. As long as I explicitly click a
link to progress, it works with browsers I've tried.

If I click the browser's back button I see the content of
the browser's location bar change as I expect. But I
need to set the visibility and display styles for the
corresponding division. In Netscape/Mozilla I have a little
function enabled by setInterval(). It looks to see if
window.location.hash matches the division which is visible
and modifies styles accordingly.

Under IE window.location.hash seems to be "stuck" at the
most "forward" link. Under Opera I can get only the URL
without the hash; it claims that the hash property is
undefined or empty. I've tried document.location and
document.URL with the same results.


Read the document.location.href and then parse it yourself. You should
know the current URL, simply remove that from the string and then read
the rest.

document.location.search might be an alternative, it would require you
use the ? instead of the #

Jul 23 '05 #2
>> ...
Under IE window.location.hash seems to be "stuck" at the
most "forward" link. Under Opera I can get only the URL
without the hash; it claims that the hash property is
undefined or empty. I've tried document.location and
document.URL with the same results.
Read the document.location.href and then parse it yourself. You

should > know the current URL, simply remove that from the string and
then read > the rest.
document.location.search might be an alternative, it would require

you > use the ? instead of the #

Thanks for the thoughts. But document.location.href shows the
same situation as document.location.hash and parsing it myself
would make no difference. (In fact, for debugging I displayed
..href so I could be sure of what was going on.)

I tried passing the information in document.location.search.
That causes other behaviors in IE and Opera but I still get
the same basic problems I had before.

I decided on a different approach. If the navigation history
within the page is actually useless since the navigation bar
is always available, then window.location.replace() will
avoid a history. The back button goes to my page's referrer,
and forward would go to some other page. That also allows me
to get rid of the setInterval() and the routine it invokes.

Again, it works in Mozilla/Netscape, but not in IE and Opera.
IE *keeps* the history, and the browser's back function leaves
the wrong section visible. Opera does the right thing with
the history but insists on forcing visibility and display
for the division I'm leaving. I have an alert() immediately
after the assignment into window.location so I can see the
*correct* division displayed while the alert() is active. I
then see it revert to the division I'm leaving once I dismiss
the alert().

Here's a code snippet that shows the basic setup:

var idList = new Array("sched", "lead", "cont");

function swapVisibility(theId) {
document.location.replace("veeblefetzer.html#" + theId);
var hideIt;
for (var i=0; i<idList.length; i++) {
hideIt = document.getElementById(idList[i]);
hideIt.style.visibility = "hidden";
hideIt.style.display = "none";
}
var becomeVisible = document.getElementById(theId);
becomeVisible.style.visibility = "visible";
becomeVisible.style.display = "block";
alert(document.location.href+"\n"+theId);
return true;
} // end function swapVisibility

<a onclick="swapVisibility('sched');" href="#sched">...</a>
<a onclick="swapVisibility('lead');" href="#lead">...</a>
<a onclick="swapVisibility('cont');" href="#cont">...</a>

<div id="sched">
...
</div>
<div id="lead">
...
</div>
<div id="cont">
...
</div>

etc.

Am I using document.location.replace() correctly?
Jul 23 '05 #3
I think I can describe the solution to the problem as
breaking out of a Netscape V4 mindset. Instead of
changing visibility as part of an anchor tag, I use
the onClick within a paragraph tag. That immediately
gets rid of the navigation history in all browsers.
document.location.replace() is gone.

There's an option to view all sections at once. If
that's enabled, I shove the target location (hash)
into document.location. That gets back into the
navigation history again, but that's acceptable in
what is now a longish page.

The browser incompatibilities, well, chalk 'em up to
something else to remember for future work. This
approach is much cleaner, not just a "workaround."
Jul 23 '05 #4
Richie wrote:
I think I can describe the solution to the problem as
breaking out of a Netscape V4 mindset. Instead of
changing visibility as part of an anchor tag, I use
the onClick within a paragraph tag. That immediately
gets rid of the navigation history in all browsers.
document.location.replace() is gone.


location is a property of the default window object, so it's
window.location.replace(). document.location is deprecated, has
been for a long time.

<url:
http://devedge.netscape.com/library/.../document.html
/>
"Do not use location as a property of the document object; use
the document.URL property instead. The document.location
property, which is a synonym for document.URL, is deprecated."

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #5
Grant Wagner wrote:
Richie wrote:

I think I can describe the solution to the problem as
breaking out of a Netscape V4 mindset. Instead of
changing visibility as part of an anchor tag, I use
the onClick within a paragraph tag. That immediately
gets rid of the navigation history in all browsers.
document.location.replace() is gone.

location is a property of the default window object, so it's
window.location.replace(). document.location is deprecated, has
been for a long time.

<url:
http://devedge.netscape.com/library/.../document.html
/>
"Do not use location as a property of the document object; use
the document.URL property instead. The document.location
property, which is a synonym for document.URL, is deprecated."

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


I tried all three variations along the way. Apologies for
using the deprecated property in my description.
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mmac | last post by:
I am trying to create something like this: Response.Write "<a href=""javascript:openWindow('www.domain.com/events/EventDetails.asp?EventID=" & rsEvents("OccID") &...
2
by: jeff | last post by:
Hello, I'm building an internal web application using HTML/PHP/Javascript. The system is flexible to the point where the user can have as many browser windows open for each part of the system. ...
2
by: Ed Schimmel | last post by:
Hi All, I have a small question considiring the opening of a new window in javascript. As you all know the code below will open a new without any bars. But when I tried this code in IE6 it won't...
21
by: Albretch | last post by:
Hi, client wants for a window with no toolbars to open (technical and 'esthetical' reasons) after the window, user clicks on, is being closed. I told them about security settings in browsers...
7
by: E Michael Brandt | last post by:
I have been lurking here for some time, and now would like to ask a question of you clever coders: My JustSo PictureWindow 3 Extension for Dreamweaver has stumbled in the face of the new Opera...
3
by: Bob | last post by:
I am trying to create a popup page (to act as a menu) from a parent page. When the parent page (index.jsp) calls my popup function (see below) it will properly open the correct size browser window...
2
by: Matt | last post by:
When we submit the form data to another page, we usually do the following: <form action="display.aspx" method="post"> will submit the form data and open display.asp in the current browser ...
4
by: sid | last post by:
"about:blank" oepns new browser window I am writing a webpage that will run on other machines that I may or may not know about. My page is framed where frame1 controls the content of frame2. ...
1
by: captainwin | last post by:
Here's the problem: - Website is ASP.NET 1.0 - Server is Windows Server 2003 - Browser is IE 6/7 - Client requests a mail merged MS Word 97 - 2003 document on the website, and the document gets...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.