Results 1 to 1 of 1

Thread: Sometimes things work, sometimes they don't...?

  1. #1
    Join Date
    Sep 2011
    Bristol, England, United Kingdom

    Sometimes things work, sometimes they don't...?

    Hi all,

    I've noted this strange phenomenon recently when working with JavaScript and have no idea why it happens or what I can do about it. I don't know what the problem is so I can't give it a name, but I'll give an example or two:

    I was using window.innerHeight and window.innerWidth to calculate the correct size for a transparent "blackout" <div>. It blacked out the screen so and an options box was displayed on top of it. A few days later, on a seperate file and seperate project, I used the same functions to calculate the document size, but got values of 0 being returned every time. I then had to use document.body.clientHeight and document.body.clientWidth to calculate the document size instead. The annoying thing is, neither one worked in the other project.

    Another example:

    I am using some scripting to enable BB tag use in an editor I've built and am using JavaScript's selection object to find the selected text and wrap BB tags around it. I have a logical condition to enable detection of browsers because as most people are well aware, IE has a differernt selection object to the others. So, the code for EI is document.selection, while the code for the rest uses the selectionStart and selectionEnd objects. So, here's the issue: I commented out the IE code for test purposes and totally forgot that I'd commented it out. I uploaded my files to my server and tested out my editor; it worked fine and BB tags were wrapping nicely. However, I sent the link to my brother to test out the editor on his machine and code didn't work. I know... obviously it didn't work, it was commented out! But then how did it work for me? It wasn't cached, it was a new upload. Therefore, my PC was using the code for Chrome, FF, etc. under the IE browser.

    I'm not expecting answers to the above problems because they've been sorted out and are no longer problems. What I'm confused about is why a function/object will work one day, then the next, in a seperate project, they don't work. My first example of getting client document sizes is perfect. I am currently working on a 2nd project where I would like to get the client document size and am having to use the seperate objects to return height, whereas in my other project I am using the aforementioned ones.

    Can anyone enlighten me as to what could be going on? Doctypes? any declarations I've not considered? Anything?

    Last edited by George88; 02-28-2012 at 11:10 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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