Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Compaibility issue: window.location mismatch with browser locationbar

Reply
Thread Tools

Compaibility issue: window.location mismatch with browser locationbar

 
 
spam_me_ not
Guest
Posts: n/a
 
      07-29-2004
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.
 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      07-29-2004
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 #

 
Reply With Quote
 
 
 
 
spam_me_ not
Guest
Posts: n/a
 
      07-29-2004
>> ...
>> 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?
 
Reply With Quote
 
Richie
Guest
Posts: n/a
 
      07-30-2004
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."
 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      07-30-2004
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 <(E-Mail Removed)>
comp.lang.javascript FAQ - http://jibbering.com/faq

 
Reply With Quote
 
Richie
Guest
Posts: n/a
 
      08-03-2004
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 <(E-Mail Removed)>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplex Mismatch?? Darrell Wireless Networking 2 12-13-2005 02:52 AM
Locationbar Object ZER0 Javascript 3 07-07-2004 09:51 AM
Type mismatch using Mozilla ActiveX in place of Microsoft WebBrowser? Noozer Firefox 0 05-19-2004 08:08 AM
How do you put back the locationbar and menubar from within your own page NoSpammingToMePlease@bahnhofbredband.se Javascript 3 11-14-2003 03:10 PM
mod_perl errors: prototype mismatch ... during global destruction ian douglas Perl 0 08-18-2003 11:17 PM



Advertisments