gish Posted October 18, 2007 Share Posted October 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 18, 2007 Share Posted October 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
gish Posted October 19, 2007 Author Share Posted October 19, 2007 Thankyou for your help, I have doing some reading I think I might change to object as that is more compliant. gish Quote Link to comment Share on other sites More sharing options...
gish Posted October 22, 2007 Author Share Posted October 22, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.