javascript - How to get style coordinates of element in IE8 -
i have been banging head @ while need smart guys.
i struggling extract xy coordinates of 'background-position' value in element. test this, set (css_class = predetermined css class):
var d = document.getelementbyid(css_class); alert("1: "+getstyle(d,'background-position')); alert("2: "+d.style.backgroundposition); alert("3: "+d.currentstyle.backgroundposition); alert("4: "+d.style.csstext); alert("5: "+window.getcomputedstyle(d,null).getpropertyvalue('background-position')); test1--> undefined test2--> blank test3--> undefined test4--> blank test5-->'object doesn't support property or method 'getcomputedstyle''
nothing gives me xy pixel values. have done research, through microsoft dom api references find, here (which got getstyle function (below, uses getcomputedstyle), searched mozilla developer forums, etc. function found on forum:
function getstyle(el,styleprop) { var camelize = function (str) { return str.replace(/\-(\w)/g, function(str, letter){ return letter.touppercase(); }); }; if (el.currentstyle) { return el.currentstyle[camelize(styleprop)]; } else if (document.defaultview && document.defaultview.getcomputedstyle) { return document.defaultview.getcomputedstyle(el,null) .getpropertyvalue(styleprop); } else { return el.style[camelize(styleprop)]; } }
basically i'm pretty sure issue because ie 11 browser reverts ie8 mode (says in developer console). of these work in chrome , mozilla fine. i'm testing in ie8 because customers still use ie 8. also, appears server side code (this sharepoint server don't have full rights on) forcing page display in ie8 mode.
i tried add html5 tag <!doctype html>
maybe force browser render in html5. still stuck on ie8 mode. anyways, can point me dom api call work , pull out pixel values in ie8?
i made test page background-position defined in inline style, , able pick in .style.backgroundposition property. (i did have click button enable javascript, since it's local file.)
<html> <head> <meta http-equiv="x-ua-compatible" content="ie=8"> <title>ie8 test</title> </head> <body> <div id="a" style="width: 200px; height: 200px; border: 1px outset gray; background-image: url('./untitled.png'); background-position: 10px 10px;"></div> <script> document.write(document.getelementbyid("a").style.backgroundposition); </script> </body> </html>
Comments
Post a Comment