473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 7483
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.