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
https://forums.phpfreaks.com/topic/73761-solved-javascript-and-opera-9/
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

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.