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

Discussion in 'Javascript' started by Jerry Manner, Jun 24, 2005.

  1. Jerry Manner

    Jerry Manner Guest

    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
     
    Jerry Manner, Jun 24, 2005
    #1
    1. Advertisements

  2. Try to assign to the property e.g.
    location.href = "ProductL.htm"
    your code looks like a function call.
     
    Martin Honnen, Jun 24, 2005
    #2
    1. Advertisements

  3. Jerry Manner

    Jerry Manner Guest

    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?
     
    Jerry Manner, Jun 25, 2005
    #3
  4. Jerry Manner

    Lee Guest

    Jerry Manner said:
    No, it works in all versions. Post *exactly* what you are trying.
     
    Lee, Jun 25, 2005
    #4
  5. Jerry Manner

    Jerry Manner Guest

    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.
     
    Jerry Manner, Jun 25, 2005
    #5
  6. Jerry Manner wrote:

    What happens there, any error messages?
    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.

    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.
     
    Martin Honnen, Jun 25, 2005
    #6
  7. Jerry Manner

    Jerry Manner Guest

    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'
     
    Jerry Manner, Jun 25, 2005
    #7
  8. Jerry Manner wrote:

    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.
     
    Martin Honnen, Jun 26, 2005
    #8
  9. "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';
     
    Christopher J. Hahn, Jun 26, 2005
    #9
  10. 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.

    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.
     
    Richard Cornford, Jun 26, 2005
    #10
  11. Jerry Manner

    Jerry Manner Guest

    <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
     
    Jerry Manner, Jun 26, 2005
    #11
  12. [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.
     
    Christopher J. Hahn, Jun 27, 2005
    #12
  13. What happens if you use
    window.location.href = 'someFile.html';
    instead?
     
    Christopher J. Hahn, Jun 27, 2005
    #13
  14. Jerry Manner

    Jerry Manner Guest

    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!!!!
     
    Jerry Manner, Jun 27, 2005
    #14
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.