Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8996587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:46:27+00:00 2026-06-15T23:46:27+00:00

The code that i am working on is this- var winW; if (document.body &&

  • 0

The code that i am working on is this-

var winW;
if (document.body && document.body.offsetWidth) {
 winW = document.body.offsetWidth;
}
if (document.compatMode=='CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth ) {
 winW = document.documentElement.offsetWidth;
}
if (window.innerWidth && window.innerHeight) {
 winW = window.innerWidth;
}
if (winW = 1265) {
function setPosition()
{
document.getElementById("wblogo").style.left="1050px";
}
}

The code works perfectly when i use it with the onload event in the body tag.

But i want to use this when the page is being loaded. So i used the following code-

var winW;
if (document.body && document.body.offsetWidth) {
 winW = document.body.offsetWidth;
}
if (document.compatMode=='CSS1Compat' &&
    document.documentElement &&
    document.documentElement.offsetWidth ) {
 winW = document.documentElement.offsetWidth;
}
if (window.innerWidth && window.innerHeight) {
 winW = window.innerWidth;
}
if (winW = 1265) {
document.getElementById("wblogo").style.left="1050px";
}

But this code doesn’t work. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:46:28+00:00Added an answer on June 15, 2026 at 11:46 pm

    My guess is that when you removed the onload, you left your script in the head section of the document. The elements you’re trying to work with (document.body, your wblogo element) don’t exist yet, so the code can’t interact with them. When you were using onload, your code wasn’t being run right away, but instead very late in the page load cycle after all images and such were loaded, and so the elements did exist.

    Instead, put your code in a script tag at the end of your document, just before the closing </body> tag. That way, the elements you’re trying to work with will exist.

    More:

    • YUI Best Practices for Speeding Up your Website
    • Google on when DOM elements are available
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with some code that does this: var _init = false; this.init =
I had this working in an old code that I didn’t end up using...
Hi I have been working on this code that creates a table with radio
I've recently been working with code that looks like this: using namespace std; class
I have code that works fine: var myValue = $(this).parents('tr:first').find('td:first').text(); is there anyway to
I have this code that is working in all browsers, but for some reason
This is the code that is working but not the way i need it
I have this bit of code that is working in FF, Chrome, Safari, and
I have this code that is working fine for me: using System; using System.Collections.Generic;
This is my code that is working fine when I'm sending it to one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.