The formula is a bit long but works: function round(x) { return parseFloat(Math.round(x * 10) / 10).toFixed(1).replace(/\.0/, « ») } round(458.21456); // -> 458.2 round(500); // -> 500 round(603.18); // -> 603.2
Étiquette : Niveau débutant
Breadcrumb / steps in CSS that works from IE8 [CSS]
I was looking for a simple code for a step by step process indicator. I found a few things, but everyone seems to have forgotten about IE8… I need to support this old browser at work. So I did my own that I’m sharing here: File Uploaded → File Reviewed → File Approved And the […]
Communication between iframe and parent window [JavaScript]
In the iframe you’ll use the below code: window.parent.postMessage(« Hello World ! », « http://your.site.web »); And in the parent window: // function that will be called when the message is received function receiveMessage(event) { alert(event.data); // it’ll show « Hello World ! » } // we listen to a message if (window.addEventListener) { window.addEventListener(‘message’, receiveMessage, false); } else if (window.attachEvent) […]
Use hash word in the Sharepoint navigation
Let’s say you have the url http://my.site.com/myfolder/mypage.aspx#hash and you want to use it as a link into your left navigation bar in Sharepoint…. If you try putting that name, Sharepoint will not keep your link. The trick here is to add a questionmark juste before the #. The URL to use will be http://my.site.com/myfolder/mypage.aspx?#hash and […]
Tiny AJAX
This is a very tiny javascript code to do an AJAX Request: /* m: method (« get », « post ») u: url a: async (true) or sync (false) c: callback (with ‘xhr’ as a parameter) d: post_data (the data to post) */ function tiny_ajax(m,u,a,c,d){with(new(this.XMLHttpRequest||ActiveXObject)(« Microsoft.XMLHTTP »))onreadystatechange=function(){readyState^4||c(this)},open(m,u,a),send(d)} And an example: tiny_ajax(‘get’, ‘http://www.google.com’, true, function(xhr) { alert(xhr.responseText) })
How to change the Firefox portable main window icon? [Astuce]
If you use Firefox Portable in the same time as the regular Firefox, then it can be annoying to see the same icons for the both Firefox. You can easily change the icon for the main window of the portable version of Firefox. Just find the .ico you want to use and place it into […]
Override SharePoint OOTB Upload.aspx default for « Add as a new version to existing files » checkbox
With Sharepoint, when we want to upload a file, the « Add as a new version to existing file » is checked by default, and that could be an issue for you. Here is a JavaScript fix to add into your masterpage, just before the </head> tag : <script type= »text/javascript »> function DefaultUploadOverwriteOff() { if (document.title.indexOf(« Upload Document ») > […]
Requête MySQL insensible aux accents
Pour effectuer une requête MySQL qui ne sera pas sensible aux accents (par exemple ‘ö’ = ‘o’ ou ‘à’ = ‘a’) il faut rajouter le mot clé COLLATE avec la bonne collection. Après plusieurs tests, j’utilise la collection utf8_general_ci. Ce qui donnera : SELECT ID, Nom FROM Inscrits WHERE Nom LIKE ‘%heracles%’ COLLATE utf8_general_ci ORDER […]
Déplacer le volet de détails en bas sous Windows 8 [Astuce]
Windows 8 apporte différentes nouveautés, dont dans l’explorateur. Malheureusement ces modifications ne sont pas toujours les bienvenues… Par exemple le volet de détails apparait désormais à droite et non plus en bas de la fenêtre, ce qui n’est pas pratique et mange de la place. Heureusement il existe un moyen de la déplacer vers le […]
Google Analytics : les recommandations de la CNIL [JavaScript]
La loi a changé concernant les cookies déposés chez les utilisateurs. Pour cela la CNIL a créé une page qui explique ce qu’il en est. Ils proposent même un bout de code pour le opt-in et le opt-out, que j’ai légèrement modifié : // Remplacez la valeur UA-XXXXXX-Y par l’identifiant analytics de votre site. var […]