Forum Moderators: open
In that thread, whoisgregg got me thinking about keeping track of exactly how far they had scrolled as well.
Using some code he posted as well as some other code I found, that is easy enough to do, but then I realized that the scroll length would be pretty heavily affected if a person wasn't using the standard text size when viewing the page (yes, screen size also has an affect, but my layout is fixed so it is negligible in comparison to text size changes).
Is there a way of using some js to detect if the person is using something other than the default text size so I can not factor in their stats and keep from skewing the results?
Thanks!
This will give you the 1 em pixel size of the body font being used.
textNode?
Offsets?
Must have slept through that class.
Anyway, this page is designed using pts with most paragraph text, bullet points, etc. in 10pt Arial, with headings in slightly larger pts.
So...is there any way to know if a visitor that hits my site is seeing the page as exactly as I have set, or if it is being altered because the user has his/her browser set to increased text size?
var emSize;
var emSizeDiv;function installEMsize() {
var body = document.body;
var div = document.createElement( "DIV");div.style.position = "absolute";
div.style.top = "10px";
div.style.right = "10px";
div.style.display = "none";div.style.margin = 0;
div.style.padding = 0;
div.style.borderWidth = 0;div.style.lineHeight = "1em";
div.setAttribute( "id", "fixmarginemsize");
div.appendChild( document.createTextNode( "M"));body.appendChild( div);
emSizeDiv = document.getElementById( "fixmarginemsize");
}function getEMsize() {
if(!emSizeDiv) installEMsize();emSizeDiv.style.display = "block";
emSize = emSizeDiv.offsetHeight;
emSizeDiv.style.display = "none";return emSize;
}
Just call getEMsize whenever you want. It returns the size of 1em in px, accounting for browser font size, and any font size definition.
It returns emSize, but the variable is also global so you can just reference it when you like. The function to insert the hidden DIV is called automatically.
It's worth setting an interval to check every 250ms if it's changed, there is no event to tell you when the font size has changed.