473,327 Members | 2,112 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,327 software developers and data experts.

document.URL functionality

alu
Could someone explain the discrepancies within and between the stated
definitions / usage of 'document.location' , 'document.URL' vs. their actual
functionality?
Should they be read-only when in fact they are not?
Is 'document.URL' also deprecated, and should therefore never be used?
What is the last word re: the proper syntax for returning and setting the
current window's location?
We have:
document.location
document.location.href
document.URL
window.location
window.location.href
location
location.href
The documentation:
-------------------------------

http://www.faqts.com/knowledge_base/view.phtml/aid/6702
"document.location is deprecated and should never be used.
Instead, either use document.URL or window.location.href."

http://webreference.com/programming/...t/jf/column10/
"Location is not a property of the document object; its equivalent is the
document.URL property. The document.location property, which is a synonym
for document.URL, is deprecated. Instead, the 'location.href' or
'window.location.href' property should be used."
http://www.mozilla.org/docs/dom/domr...6.html#1025116
"document.location works the same as document.URL. Both are read-only
properties unlike window.location, which can be set."
"URL is a replacement for the DOM Level 0 document.location.href property.
However document.URL is not settable, unlike document.location.href."


Actual test results:
------------------------------

IE/Win local:

document.location: file:///T:/frameset/mainframe.html?test (settable)

document.URL: file://T:\frameset\mainframe.html (settable -
note lack of query string and backslashes)

------------------------------

IE/Win live:

document.location: http://home.prims.com/x/mainframe.html?test
(settable)

document.URL: http://home.prims.com/x/mainframe.html?test
(settable - note query string appears)

------------------------------

FF/Win local:

document.location: file:///T:/frameset/mainframe.html?test
(settable)

document.URL: file:///T:/frameset/mainframe.html?test
(read-only)
FF/Win live:

-----------------------------

document.location: http://home.prims.com/x/mainframe.html?test
(settable)

document.URL: http://home.prims.com/x/mainframe.html?test
(read-only)
Aug 2 '05 #1
9 36693
alu wrote:
Could someone explain the discrepancies within and between the stated
definitions / usage of 'document.location' , 'document.URL' vs. their actual
functionality? document.location vs window.location These are usually just pointers to the same object.
document.URL vs document.location.href URL is readonly, href can be set
window.location vs location location refers to window.location if no other in scope.
Just like alert refers to window.alert.
document.location vs document.location.href

Assigning to document.location will (usually) also update the href
property. Therefore there is not really any difference.

The most cautious way to set the location is probably through
window.location.href
Aug 3 '05 #2
VK

alu wrote:
Could someone explain the discrepancies within and between the stated
definitions / usage of 'document.location' , 'document.URL' vs. their actual
functionality?
Should they be read-only when in fact they are not?
Originally (LiveScript - JavaScript 1.1) window.location was read-only
and document.location was read-write. Now they both are read-write.
This definitely makes easier to manupulated framed sites.
Is 'document.URL' also deprecated, and should therefore never be used?
It is not deprecated, just an opposite it is rather newly introduced as
substitution for document.location.href = newURL.
But I would not suggest to use it as being one of ugly and unwanted
children of W3.
What is the last word re: the proper syntax for returning and setting the
current window's location?
location is not a property. It's an object with a set of read-write
string properties:
href : the whole URL string
protocol : http:, shttp:, file: etc.
host : host name and port number (if presented)
hostname : host name (if no post number, then == host)
port : port number
pathname : all between host and including the actual http page
hash : anchor mark (what follows # sign)
search : CGI request (what follows ? sign)

All these parts can be read or change independently.
The default property of location is href. So if you assign:
document.location = newURL
internally browser will treat it as:
document.location.href = newURL

This way
document.location = newURL
document.location.href = newURL
document.URL = newURL
are alias of the same action.
From the other side location is in use since the beginning of script

and it allows you fine-graned access/change of of the URL parts.
document.URL is a rather late invention of someone bored mind. It
doesn't give you anything extra, but it takes out a lot. Just forget it.

Aug 3 '05 #3
alu

"Robert" <ro****@noreply.x> wrote
alu wrote:
Could someone explain the discrepancies within and between the stated
definitions / usage of 'document.location' , 'document.URL' vs. their actual functionality?
> document.location vs window.location

These are usually just pointers to the same object.


But document.location is deprecated.
> document.URL vs document.location.href

URL is readonly, href can be set


Theoretically only. The tests I posted showed otherwise.

> window.location vs location

location refers to window.location if no other in scope.
Just like alert refers to window.alert.


That cuts down the confusion -thanks.

> document.location vs document.location.href

Assigning to document.location will (usually) also update the href
property. Therefore there is not really any difference.


But document.location is deprecated.

The most cautious way to set the location is probably through
window.location.href


That's what I was hoping.
-alu
Aug 3 '05 #4
VK wrote:
alu wrote:
[...]
Is 'document.URL' also deprecated, and should therefore never be used?

It is not deprecated, just an opposite it is rather newly introduced as
substitution for document.location.href = newURL.
But I would not suggest to use it as being one of ugly and unwanted
children of W3.


document.URL was in DOM 1, so it's no newer than DOM itself. You are
quite correct that it's not depreciated, however it is readonly and
therefore not really a substitute for document.location.href.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-46183437>

[...]

--
Rob
Aug 3 '05 #5
On 03/08/2005 15:07, alu wrote:

[snip]
document.URL vs document.location.href

URL is readonly, href can be set


Theoretically only. The tests I posted showed otherwise.


The URL property /is/ read-only and should be treated as such,
irrespective of whether some browsers treat it otherwise. Use the global
location object to assign new URLs.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Aug 3 '05 #6
alu

"VK" <sc**********@yahoo.com> wrote
alu wrote:
Could someone explain the discrepancies within and between the stated
definitions / usage of 'document.location' , 'document.URL' vs. their actual functionality?
Should they be read-only when in fact they are not?
Originally (LiveScript - JavaScript 1.1) window.location was read-only
and document.location was read-write. Now they both are read-write.
This definitely makes easier to manupulated framed sites.

Not according to the Mozilla documentation, which states document.location
is read-only.
Is 'document.URL' also deprecated, and should therefore never be used?


It is not deprecated, just an opposite it is rather newly introduced as
substitution for document.location.href = newURL.
But I would not suggest to use it as being one of ugly and unwanted
children of W3.

I agree, it's behaviour is flakey at best.

What is the last word re: the proper syntax for returning and setting the current window's location?


location is not a property. It's an object with a set of read-write
string properties:
href : the whole URL string
protocol : http:, shttp:, file: etc.
host : host name and port number (if presented)
hostname : host name (if no post number, then == host)
port : port number
pathname : all between host and including the actual http page
hash : anchor mark (what follows # sign)
search : CGI request (what follows ? sign)

All these parts can be read or change independently.
The default property of location is href. So if you assign:
document.location = newURL
internally browser will treat it as:
document.location.href = newURL

But document.location is deprecated - why use it at all?

This way
document.location = newURL
document.location.href = newURL
document.URL = newURL
are alias of the same action.

In practice they are definitely not the same. Check the tests I posted.

From the other side location is in use since the beginning of script
and it allows you fine-graned access/change of of the URL parts.
document.URL is a rather late invention of someone bored mind. It
doesn't give you anything extra, but it takes out a lot. Just forget it.


Excellent.
-alu
Aug 3 '05 #7
I too was under the impression that document.location was deprecated, or
at least not as compatible as window.location.

How do I know when to use either window.location or window.location.href
?

Later, Art.

Aug 4 '05 #8
X l e c t r i c wrote:
I too was under the impression that document.location was deprecated, or
at least not as compatible as window.location.

How do I know when to use either window.location or window.location.href
?


Always use window.location.href
Although I do not know any case in which window.location does not work.
Aug 4 '05 #9
Robert wrote:
X l e c t r i c wrote:
I too was under the impression that document.location
was deprecated, or at least not as compatible as
window.location.

How do I know when to use either window.location or
window.location.href ?


Always use window.location.href
Although I do not know any case in which window.location
does not work.


There were some versions of IE 4 that did not respond well to
assignments to location, but did work with assignments to location.href.
On the other hand, some early releases of IE 6 did not respond to
assignments to location.href, where they would work with assignments
directly to location.

Generally, I would go for assigning to location, and reading URLs form
location.href. That would be particularly true when trying to navigate
other frames or windows where the content may be from another domain
(less chance of provoking cross-domain security restrictions, and that
is also the main practical reason for never using document.location at
all (as the document will always be inaccessible cross-domain), apart
from the fact that document.locatrion is not as widely implemented as
the location property of the global/window object.).

Whether location needs additional qualification as a property of the
window object depends on the current scope. The additional property
look-up will add a (very) slight overhead, but avoid an unqualified
identifier resulting in an error in environments that do not provide a
location object (though nobody has ever been able to identify such an
environment). I would only qualify the location in cross-frame
scripting, where the qualifier would be something other than 'window'.

Richard.
Aug 4 '05 #10

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

Similar topics

3
by: Suresh Kumaran | last post by:
How do you program in VB.NET to show the most recent used document in a dropdown menu? I am referring to something like in MS WORD or EXCEL where it shows the recent document the user was working...
6
by: 2obvious | last post by:
This is a pipe dream, I realize, but I'm trying to emulate the functionality of the W3C DOM-supported document.getElementsByTagName method under the very nightmarish Netscape 4. Through some...
6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
3
by: Hermit Crab | last post by:
I'm seeing some unexpected (at least to me) behavior in the 'window' and 'document' objects under Netscape 7.1 and Internet Explorer 6.0. When a property is added to the prototype for 'Object',...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
17
by: rox.scott | last post by:
Can someone please explain why this happens? The expected output is 3, but uncommenting line 7 makes the output 0. Why ??? VB.NET code: ** note the commented line, this is the culprit ** Dim...
4
by: Andrew Robinson | last post by:
This might be more of an IIS question but is there a way of hosting a document (think Word or Excel) within a web site that allows a user to not only download and edit it but also save changes...
8
by: dhtml | last post by:
Other than Safari 2, what other browsers that support document.clientHeight ? I would guess some KHTML did. I have found the feature, when it is present, to reliably provide the height of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.