Jump to content

[SOLVED] javascript and opera 9


gish

Recommended Posts

hi everyone

 

I have got some javascript that works in every browser i have got except for opera. i don't think that this piece of code is working i debug with firebug and have looked at the opera error console and there are nothing wrong with a the script.

 

getWindowCoords = (navigator.userAgent.toLowerCase().indexOf('opera')>0||navigator.appVersion.toLowerCase().indexOf('safari')!=-1)?function() {
  canvasX = window.innerWidth;
  canvasY = window.innerHeight;
				}:function() {
  canvasX = document.documentElement.clientWidth||document.body.clientWidth||document.body.scrollWidth;
  canvasY = document.documentElement.clientHeight||document.body.clientHeight||document.body.scrollHeight;
}

 

The code has to work so that it can resize and reposition buttons for ajax. The buttons and ajax work fine.

 

Does anyone have any suggestion why it won't work.

 

Gish

Link to comment
Share on other sites

Ternaries are cool, but "should" only be used to set one or another value. (http://javascript.crockford.com/style2.html). You could easily just use the "else" in y our example and extend the "or" clause

 

And why not use an object:

 

windowCoords = {

x: window.innerWidth || document.documentElement.clientWidth||document.body.clientWidth||document.body.scrollWidth,

y: window.innerHeight || document.documentElement.clientHeight||document.body.clientHeight||document.body.scrollHeight

};

 

windowCoords.x;

 

I dont have opera 9 installed though, but i do hope that this could help you

 

 

Link to comment
Share on other sites

The problem was the function was not been read by opera.

 

the new formated script fix the issue

// "document.body.clientWidth" and "document.body.clientHeight"
   var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
     //Non-IE
   myWidth = window.innerWidth;
   myHeight = window.innerHeight;
  } 
else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
   myWidth = document.documentElement.clientWidth;
   myHeight = document.documentElement.clientHeight;	
} 
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
  myWidth = document.body.clientWidth;
  myHeight = document.body.clientHeight;
}
		canvasX = myWidth;
	canvasY = myHeight;

 

the script is a howto  that has been modified by me

 

gish

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.