SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE giving "object required" error.

    I have a script that picks up some screen size info then sends it via AJAX to the server for logging. It works properly in FF and Opera, but IE 6 & 7 give me an "object required" error at the first "var". What is causing this and how can I fix it?
    <script type="text/javascript">
    var iWidth = (window.innerWidth) ? window.innerWidth
    : document.body.offsetWidth;
    var iHeight = (window.innerHeight) ? window.innerHeight
    : document.body.offsetHeight;
    var screenW = screen.width;
    var screenH = screen.height;

    Stephen

    p.s. I did not write the script.

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try: document.body.parentNode.offsetWidth

    I believe you will find that to work in all current user agents.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the answer JVLB. Unfortunately, the issue remains.

    Stephen

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to wait until the window has loaded; try this:

    window.onload=function(){
    alert(document.body.parentNode.offsetWidth);
    }

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I have fixed the problem. JVLB, I tried your suggestion and the original error is gone but it said that the variables I set were not defined when I tried to use them. So, I reorganized the script and put the variable declarations into the beginning of my AJAX function. Now it works flawlessly. I'm really not sure why I didn't have it this way in the first place but, I do now.

    Stephen


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •