location.reload() don't work?
-
- Posts: 9
- Joined: August 10th, 2005, 7:33 am
location.reload() don't work?
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?
<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
- Posts: 578
- Joined: April 28th, 2004, 7:25 pm
- Location: California
- Contact:
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.
That said, Mozilla does support the onresize property and document.location.reload();. Note that that's document.location, not window.location.
Web browser standards support tables
Internet Explorer is dangerous
Web Devout - Promote standards and the health of the Web
Internet Explorer is dangerous
Web Devout - Promote standards and the health of the Web
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
window.location.reload() WFM.
In fact, location.reload() is enough
it's body.onresize that's not supported.
window.onresize is supported
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.
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.
-
- Posts: 9
- Joined: August 10th, 2005, 7:33 am
-
- Posts: 9
- Joined: August 10th, 2005, 7:33 am
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
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...
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...
-
- Posts: 0
- Joined: December 31st, 1969, 5:00 pm
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.
-
- Posts: 9
- Joined: August 10th, 2005, 7:33 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>
<!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
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
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.
-
- Posts: 0
- Joined: December 31st, 1969, 5:00 pm
-
- Posts: 9
- Joined: August 10th, 2005, 7:33 am
-
- Posts: 0
- Joined: December 31st, 1969, 5:00 pm
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?
Why are you trying to do this, anyway?
- jqp
- Posts: 5070
- Joined: November 17th, 2004, 10:56 am
- Location: In a box
- Contact:
-
- Posts: 9
- Joined: August 10th, 2005, 7:33 am
-
- Posts: 0
- Joined: December 31st, 1969, 5:00 pm
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.
But the page is resizing and that would break all the sane onresize implementations.
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.