What is the right IE version for command location.href?

J

Jerry Manner

Hi

I have a problem using the location.href("ProductL.htm") javascript
code. Using this code on my system ( W98 SE, IE 6.0) is working
correctly.
But if a user has W2000 IE 5.0 it doesn't work. When using this code
the browser shows an error on page in the statusbar. If I click on the
statusbar to find out what is causing the error I see this description
'The property of this method is not supported by this object' ( I have
translated this in English, my IE browser is in dutch)

Does the location.href only work for a certain version of IE?

Regards
 
M

Martin Honnen

Jerry said:
I have a problem using the location.href("ProductL.htm") javascript
code.

Try to assign to the property e.g.
location.href = "ProductL.htm"
your code looks like a function call.
 
J

Jerry Manner

Hi

I have tried what you said, but that gave me the same result. Is
location.href only working for a certain version of IE?
 
L

Lee

Jerry Manner said:
Hi

I have tried what you said, but that gave me the same result. Is
location.href only working for a certain version of IE?

No, it works in all versions. Post *exactly* what you are trying.
 
J

Jerry Manner

Hi

Here is the original code which is working for my system ( W98 SE, IE
6) but not for another person ( W2000, IE 5).

function CheckLogin() {

var textField = document.getElementById("T1");

if (textField.value == 'Marjolein Visser')
{
location.href("IntranetP.htm");
}
else if (textField.value == 'Hans Veerkamp')
{
location.href("IntranetELP.htm");
}
else if (textField.value == 'Steven Badle')
{
location.href("IntranetSBadleP .htm");
}
}

This function is alled from an onclick event of a image.
 
M

Martin Honnen

Jerry Manner wrote:

Here is the original code which is working for my system ( W98 SE, IE
6) but not for another person ( W2000, IE 5).

What happens there, any error messages?
function CheckLogin() {

var textField = document.getElementById("T1");

if (textField.value == 'Marjolein Visser')
{
location.href("IntranetP.htm");

As said it should be an assignment
location.href = "IntranetP.htm"
at least if you want to write cross browser code for the web, the
function call might work with an IE/Win only intranet.

location.href("IntranetSBadleP .htm");

You need to escape the space character
"IntranetSBadleP%20.htm"
in a URL, that is the only thing that I see that might cause problems.
 
J

Jerry Manner

Hi

The sapce was an error in the posting. In the code there is no space. I
did change the location.href("IntranetP.htm")­; into location.href =
"IntranetP.htm", but that resulted in the same error ''The property of
this method is not supported by this object'
 
M

Martin Honnen

Jerry Manner wrote:

The sapce was an error in the posting. In the code there is no space. I
did change the location.href("IntranetP.htm")­; into location.href =
"IntranetP.htm", but that resulted in the same error ''The property of
this method is not supported by this object'

I am not sure what could be causing this and therefore have to keep
suggesting other attempts as a guess work, you could try whether
directly assigning
location = "IntranetP.htm";
solves that problem. The location object is a bit magical in allowing an
assignment to itself when you want to set the href property.
 
C

Christopher J. Hahn

Jerry said:
Hi

I have a problem using the location.href("ProductL.htm") javascript
code. Using this code on my system ( W98 SE, IE 6.0) is working
correctly.
But if a user has W2000 IE 5.0 it doesn't work. When using this code
the browser shows an error on page in the statusbar. If I click on the
statusbar to find out what is causing the error I see this description
'The property of this method is not supported by this object' ( I have
translated this in English, my IE browser is in dutch)

Does the location.href only work for a certain version of IE?

Regards

"Object doesn't support this property or method" is the error we'd see
in English browsers. Essentially, the location object (if it exists)
doesn't have a member named href.

Since all versions of IE since and including at least 4.0 support the
location object and the href member of it, this suggests to me that the
location object you're working with is not what we might expect it to
be. For instance, if your function is being called as a member of an
object that also has a location member, then the unqualified reference
to location will refer to the object's location member and not the
window's location.

If assigning to the location object doesn't work, try fully-qualifying
it as window.location.href

window.location.href = 'File.html';
 
R

Richard Cornford

Christopher J. Hahn wrote:
Since all versions of IE since and including at least 4.0
support the location object and the href member of it,
this suggests to me that the location object you're working
with is not what we might expect it to be. For instance, if
your function is being called as a member of an object that
also has a location member, then the unqualified reference
to location will refer to the object's location member and
not the window's location.

Unqualified identifiers are resolved against the function's scope chain
so even if the function was called as a method of an object with a -
location - property the unqualified identifier would not be resolved as
a reference to that object property, unless that object had been added
to the function's scope chain explicitly.

Explicitly adding a custom JS object to the scope chain of a function
requires that the function be created in a - with - statement, which is
only possible with function expressions. The OP's posted code is not a
function expression, but might just about be an inner function
declaration inside a function expression. Though that is extremely
unlikely (and it would be another serious omission on the OP's part not
to have included the outer function(s) with the code).

Richard.
 
J

Jerry Manner

<Since all versions of IE since and including at least 4.0 support the
<location object and the href member of it, this suggests to me that
the
<location object you're working with is not what we might expect it to
<be. For instance, if your function is being called as a member of an
<object that also has a location member, then the unqualified reference

<to location will refer to the object's location member and not the
<window's location.

Hi

I call my JS function in an onclick event of an image like this
onclick="CheckLogin()". Further, if I look at the entire html code on
the page I see that the location member is only used in the JS function
I placed in my original posting
 
C

Christopher J. Hahn

Richard said:
Christopher J. Hahn wrote:


Unqualified identifiers are resolved against the function's scope chain
so even if the function was called as a method of an object with a -
location - property the unqualified identifier would not be resolved as
a reference to that object property, unless that object had been added
to the function's scope chain explicitly.
[snip]

Of course you're right. The example I cited was flawed and wouldn't
apply in this case.

I think it still stands that, given the error message, the 'location'
object being worked with probably is not the window.location we would
expect it to be. There is too little information to say exactly why
that would be in this case.

Ah well. Was hoping to contribute in some way to an unresolved question.
 
C

Christopher J. Hahn

Jerry said:
<Since all versions of IE since and including at least 4.0 support the
<location object and the href member of it, this suggests to me that
the
<location object you're working with is not what we might expect it to
<be. For instance, if your function is being called as a member of an
<object that also has a location member, then the unqualified reference

<to location will refer to the object's location member and not the
<window's location.

Hi

I call my JS function in an onclick event of an image like this
onclick="CheckLogin()". Further, if I look at the entire html code on
the page I see that the location member is only used in the JS function
I placed in my original posting

What happens if you use
window.location.href = 'someFile.html';
instead?
 
J

Jerry Manner

Hi

it is working now. If I use location.href = "somefile.htm" it sends the
user to that page. I don't know why it did not worked the first time I
used the same code. But it is working now.

Thank you all for your help!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top