Could someone explain the discrepancies within and between the stated
definitions / usage of 'document.locat ion' , '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.locati on
document.locati on.href
document.URL
window.location
window.location .href
location
location.href
The documentation:
------------------------------- http://www.faqts.com/knowledge_base/view.phtml/aid/6702
"document.locat ion 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.locati on property, which is a synonym
for document.URL, is deprecated. Instead, the 'location.href' or
'window.locatio n.href' property should be used." http://www.mozilla.org/docs/dom/domr...6.html#1025116
"document.locat ion 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.locati on.href property.
However document.URL is not settable, unlike document.locati on.href."
Actual test results:
------------------------------
IE/Win local:
document.locati on: file:///T:/frameset/mainframe.html? test (settable)
document.URL: file://T:\frameset\mai nframe.html (settable -
note lack of query string and backslashes)
------------------------------
IE/Win live:
document.locati on: 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.locati on: file:///T:/frameset/mainframe.html? test
(settable)
document.URL: file:///T:/frameset/mainframe.html? test
(read-only)
FF/Win live:
-----------------------------
document.locati on: http://home.prims.com/x/mainframe.html?test
(settable)
document.URL: http://home.prims.com/x/mainframe.html?test
(read-only) 9 36718
alu wrote: Could someone explain the discrepancies within and between the stated definitions / usage of 'document.locat ion' , 'document.URL' vs. their actual functionality?
document.locati on vs window.location
These are usually just pointers to the same object.
document.URL vs document.locati on.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.locati on vs document.locati on.href
Assigning to document.locati on 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
alu wrote: Could someone explain the discrepancies within and between the stated definitions / usage of 'document.locat ion' , '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.locati on 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.locati on.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.locati on = newURL
internally browser will treat it as:
document.locati on.href = newURL
This way
document.locati on = newURL
document.locati on.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.
"Robert" <ro****@noreply .x> wrote alu wrote: Could someone explain the discrepancies within and between the stated definitions / usage of 'document.locat ion' , 'document.URL' vs. their
actual functionality? > document.locati on vs window.location These are usually just pointers to the same object.
But document.locati on is deprecated. > document.URL vs document.locati on.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.locati on vs document.locati on.href Assigning to document.locati on will (usually) also update the href property. Therefore there is not really any difference.
But document.locati on is deprecated.
The most cautious way to set the location is probably through window.location .href
That's what I was hoping.
-alu
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.locati on.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.locati on.href.
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-46183437>
[...]
--
Rob
On 03/08/2005 15:07, alu wrote:
[snip] document.URL vs document.locati on.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.
"VK" <sc**********@y ahoo.com> wrote alu wrote: Could someone explain the discrepancies within and between the stated definitions / usage of 'document.locat ion' , '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.locati on 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.locati on
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.locati on.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.locati on = newURL internally browser will treat it as: document.locati on.href = newURL
But document.locati on is deprecated - why use it at all?
This way document.locati on = newURL document.locati on.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
I too was under the impression that document.locati on 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.
X l e c t r i c wrote: I too was under the impression that document.locati on 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.
Robert wrote: X l e c t r i c wrote: I too was under the impression that document.locati on 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.locati on at
all (as the document will always be inaccessible cross-domain), apart
from the fact that document.locatr ion 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 with.
Appreciate help.
Suresh
|
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 sleuthing, I was able to find what serves as a
document.getElementById emulator at
http://www.xs4all.nl/~ppk/js/dhtmloptions.html#versionb.
(Below is the code; this clever algorithm is painstakingly explained
at the site above.)
|
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 these
problems is using document.layers. I have Google'd for examples of how
to use the document object specifically with Mozilla, but I cannot
find anything that explains why my problems occur. Could anyone here
see through the included example...
|
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', it was my
understanding that it should be visible to all objects.
But it appears that it is NOT visible in the 'window' object of either IE or
Netscape.
It is visible in the 'document' property of Netscape, but not IE.
It is visible in...
|
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
scrollbar, you get the height of the entire document, screwing up any
chance of centering a window in the browser using these values.
Is there a way to get the height of the actual browser window and not
the entire page height?
Thanks.
| |
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 code
was littered with document.all and eval, for example, and I wanted to create
a practical list of best practices that they could easily put to use.
The above URL is version 1.0 (draft) that resulted. IMO, it is not a
replacement for the FAQ,...
|
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 xsl As New System.Xml.Xsl.XslTransform()
Dim xw As New System.IO.StringWriter()
Dim xmldoc As New System.Xml.XmlDocument()
Dim xsldoc As New System.Xml.XmlDocument()
xmldoc.Load("test.xml")
|
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 directly back to the web or
web server (without requireing a user to reupload the document?
Pretty sure that I have seen this kind of functionality within SharePoint
but I don't have a current install of that and ultimately I want to do this
myself...
|
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 viewport, excluding scrollbars.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |