MozillaZine

location.reload() don't work?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
sasha123456
 
Posts: 9
Joined: August 10th, 2005, 7:33 am

Post Posted August 10th, 2005, 7:37 am

I have something in my page depended of the browser window size. To get the page correctly displayed after resizing the window, I wrote:
<BODY ONRESIZE="window.location.reload()">
This work fine in MSIE, but Mozilla 1.7.6/Windows seemly do nothing on the window resizing. If I write
<BODY ONRESIZE="alert('onresize');window.location.reload()">
the alert box appears, but no piece of Javascript code in both <HEAD> and <BODY> sections executes.
If this a Mozilla bug or something is wrong in my code? How to get program equivalent of the Refresh button and
reexecute a code like document.write() when user is resizing the window?

Nanobot

User avatar
 
Posts: 578
Joined: April 28th, 2004, 7:25 pm
Location: California

Post Posted August 10th, 2005, 7:53 am

First of all, onresize and window.location.reload() are proprietary (nonstandard) features, meaning you should never expect them to work in all browsers.

That said, Mozilla does support the onresize property and document.location.reload();. Note that that's document.location, not window.location.

jqp

User avatar
 
Posts: 5070
Joined: November 17th, 2004, 10:56 am
Location: In a box

Post Posted August 10th, 2005, 8:18 am

window.location.reload() WFM.
In fact, location.reload() is enough
it's body.onresize that's not supported.
window.onresize is supported
Code: Select all
window.onresize = function() { location.reload(); }; // works, however annoying it might be.


I'm not a fan of document.location, because the document object is standardized and location is not a standard property of it. The window object is not standardized at all, but browsers tend to agree on what it supports. When standards do apply, I'm not keen on adding things to them. When standards don't apply: fair game.

sasha123456
 
Posts: 9
Joined: August 10th, 2005, 7:33 am

Post Posted August 10th, 2005, 8:33 am

window.location.reload() is from the "DOM level 0". Yes, this DOM is nonstandard at all, but commonly used. This is supported by both old browser brands - Netscape and MS (document.location is a much more nonstandard, marked as obsolete starting from NN3). Any replace in DOM 2? I can't find yet.

sasha123456
 
Posts: 9
Joined: August 10th, 2005, 7:33 am

Post Posted August 10th, 2005, 8:47 am

jonnyq, please read the original message before answering ;-). I think both window.onresize=... and <body onresize=...> are working,
but [window.]location.reload() don't.

jqp

User avatar
 
Posts: 5070
Joined: November 17th, 2004, 10:56 am
Location: In a box

Post Posted August 10th, 2005, 8:50 am

DOM is standardized (Document Object Model). There is no "replacement" for document.location in any DOM standard. "location" really doesn't belong in the scope of the document - it belongs in the scope of the window.

The window object, its properties, and its methods are not standardized (labeled DOM Level 0, which is almost a misleading term). Hopefully someone will standardize the window object at some point, but that's yet to come. (my vote is that ECMAScript standardize it, not W3C DOM)

I would stick to the code I gave... heck... it's one line...

old np
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted August 10th, 2005, 8:51 am

Nanobot wrote:Note that that's document.location, not window.location.

document.location is read-only. window.location is not.
http://developer.mozilla.org/en/docs/document.location

window.location.reload() works. Type javascript:window.location.reload() in the address bar to see.

sasha123456
 
Posts: 9
Joined: August 10th, 2005, 7:33 am

Post Posted August 10th, 2005, 9:12 am

Maybe a full sample page will help to undestand the problem:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript"><!--
if(!window.innerWidth) window.innerWidth=
document.documentElement && document.documentElement.clientWidth ||
document.body.clientWidth;
if(!window.innerHeight) window.innerHeight=
document.documentElement && document.documentElement.clientHeight ||
document.body.clientHeight;
alert('Screen:'+window.innerWidth+' x '+window.innerHeight);
// This is NOT reexecuted on resize !!!
// -->
</script>
</head>
<body onresize="alert('onresize event'); window.location.reload();">
Try to resize the browser window.
<script type="text/javascript"><!--
alert('I want to use document.write() to change something here');
// ...but it is NOT reexecuted also !!!
// -->
</script>

</body>
</html>

jqp

User avatar
 
Posts: 5070
Joined: November 17th, 2004, 10:56 am
Location: In a box

Post Posted August 10th, 2005, 9:14 am

location.reload() [doesn't work]

Yes it does.
Code: Select all
<button onclick="location.reload();" type="button">Reload</button>

works for me.
But oddly, I guess my code doesn't work:
Code: Select all
<script>window.onresize = function() { alert("yes"); document.location.reload(); }</script>

The alert appears, but no reload.
It appears that Firefox, for security/annoyance reasons, won't let you reload a window on a resize event. I don't see a preference to change this behavior.

old np
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted August 10th, 2005, 9:20 am


sasha123456
 
Posts: 9
Joined: August 10th, 2005, 7:33 am

Post Posted August 10th, 2005, 9:31 am

np wrote:https://bugzilla.mozilla.org/show_bug.cgi?id=285439
I don't undestand this page. Why the resolution is invalid? How to get the full description?

old np
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted August 10th, 2005, 9:39 am

Some pages did what you're trying to do. onresize fires when the find and pop-up toolbar appear. Therefore, these sites would reload whenever the user used find-as-you-type and they would reload infinitely if they included a pop-up. That's bad, so the devs disabled reloading on resize.

Why are you trying to do this, anyway?

jqp

User avatar
 
Posts: 5070
Joined: November 17th, 2004, 10:56 am
Location: In a box

Post Posted August 10th, 2005, 9:47 am

Someone mentioned that find bar should float on top of the page. I don't like that idea because it might cover up content and make the scrollbar a bit confusing.

Wouldn't there be an easier solution where they could keep the find bar from firing a resize event?

sasha123456
 
Posts: 9
Joined: August 10th, 2005, 7:33 am

Post Posted August 10th, 2005, 9:54 am

There are many other bad things like reloading on tiimer (try such page on slow link :-)). The Firefox team solution sounds like disabling
the 'for' statement because bad progammers use it to make infinite loops :-). Is a workaround exist?

old np
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted August 10th, 2005, 10:01 am

The point was that a very popular site (Washington Post) didn't work in Firefox because of it. Infinite loops are also given a way out in most cases (a prompt comes up to ask you whether to keep running) and if you gave them a solution to the halting problem, I'm sure they'd disable infinite loops altogether.

The workaround is to not do it.

jonnyq wrote:Wouldn't there be an easier solution where they could keep the find bar from firing a resize event?

But the page is resizing and that would break all the sane onresize implementations.

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 0 guests