visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: DHTML, JScript :: Can I get some browser settings from javascript ? like character size ?


By: VGR France  Date: 16/03/2007 23:39:21  English  Points: 100 Status: Answered
Quality : Excellent
Can I get some browser settings from javascript ? Like the current/selected character size ? a trick perhaps ?
By: VGR Date: 19/03/2007 07:25:48 English  Type : Comment
I found the trick of catching OnResize (on IFRAME for example) and computing height. (thanks Matt)

other ideas ?
By: Nono Date: 24/03/2007 09:35:20 English  Type : Comment
not to my knowledge. You may find this useful though :

http://alistapart.com/articles/fontresizing

demo
By: VGR Date: 24/03/2007 09:42:25 English  Type : Answer
interesting too.

I ended up using a different code snippet :

this in my HEAD section

if (TRUE) { //VGR17032007 ADDed fontsize detection echo<<<EOS <script type="text/javascript" src="textresizedetector.js"></script> <script type="text/javascript"> function init() { var iBase = TextResizeDetector.addEventListener(onFontResize,null); } //id of element to check for and insert control TextResizeDetector.TARGET_ELEMENT_ID = 'header'; //function to call once TextResizeDetector has init'd TextResizeDetector.USER_INIT_FUNC = init; var FontSize=0; function onFontResize(e,args) { FontSize=args[0].iSize; //test var demo = document.getElementById('trace'); //test alert("size="+fontSize); //demo // if the font is larger than 20 pixels, remove the multicolum CSS class //demo demo.className=((args[0].iSize)>=20)?'':'multicolumn'; } </script> EOS; } //EoAdd



and the textresizedetector.js file is the one from Lawrence Carvalho <carvalho@uk.yahoo-inc.com> :

/** * @fileoverview TextResizeDetector * * Detects changes to font sizes when user changes browser settings * Fires a custom event with the following data: * iBase : base font size * iDelta : difference in pixels from previous setting * iSize : size in pixel of text * * * @author Lawrence Carvalho carvalho@uk.yahoo-inc.com * @version 1.0 */ /** * @constructor */ TextResizeDetector = function() { var el = null; var iIntervalDelay = 200; var iInterval = null; var iCurrSize = -1; var iBase = -1; var aListeners = []; var createControlElement = function() { el = document.createElement('span'); el.id='textResizeControl'; el.innerHTML='&nbsp;'; el.style.position="absolute"; el.style.left="-9999px"; var elC = document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID); // insert before firstChild if (elC) elC.insertBefore(el,elC.firstChild); iBase = iCurrSize = TextResizeDetector.getSize(); }; function _stopDetector() { window.clearInterval(iInterval); iInterval=null; }; function _startDetector() { if (!iInterval) { iInterval = window.setInterval('TextResizeDetector.detect()',iIntervalDelay); } }; function _detect() { var iNewSize = TextResizeDetector.getSize(); if(iNewSize!== iCurrSize) { for (var i=0;i <aListeners.length;i++) { aListnr = aListeners; var oArgs = { iBase: iBase,iDelta:((iCurrSize!=-1) ? iNewSize - iCurrSize + 'px' : "0px"),iSize:iCurrSize = iNewSize}; if (!aListnr.obj) { aListnr.fn('textSizeChanged',[oArgs]); } else { aListnr.fn.apply(aListnr.obj,['textSizeChanged',[oArgs]]); } } } return iCurrSize; }; var onAvailable = function() { if (!TextResizeDetector.onAvailableCount_i ) { TextResizeDetector.onAvailableCount_i =0; } if (document.getElementById(TextResizeDetector.TARGET_ELEMENT_ID)) { TextResizeDetector.init(); if (TextResizeDetector.USER_INIT_FUNC){ TextResizeDetector.USER_INIT_FUNC(); } TextResizeDetector.onAvailableCount_i = null; } else { if (TextResizeDetector.onAvailableCount_i<600) { TextResizeDetector.onAvailableCount_i++; setTimeout(onAvailable,200) } } }; setTimeout(onAvailable,500); return { /* * Initializes the detector * * @param {String} sId The id of the element in which to create the control element */ init: function() { createControlElement(); _startDetector(); }, /** * Adds listeners to the ontextsizechange event. * Returns the base font size * */ addEventListener:function(fn,obj,bScope) { aListeners[aListeners.length] = { fn: fn, obj: obj } return iBase; }, /** * performs the detection and fires textSizeChanged event * @return the current font size * @type {integer} */ detect:function() { return _detect(); }, /** * Returns the height of the control element * * @return the current height of control element * @type {integer} */ getSize:function() { var iSize; return el.offsetHeight; }, /** * Stops the detector */ stopDetector:function() { return _stopDetector(); }, /* * Starts the detector */ startDetector:function() { return _startDetector(); } } }(); TextResizeDetector.TARGET_ELEMENT_ID = 'doc'; TextResizeDetector.USER_INIT_FUNC = null;



Do register to be able to answer

EContact
browser fav
page generated in 302.160020 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page