Posts mit dem Label Javascript werden angezeigt. Alle Posts anzeigen
Posts mit dem Label Javascript werden angezeigt. Alle Posts anzeigen

Freitag, 23. Januar 2015

Detect client speed using JavaScript

You can detect how long it toke for the browser to load the page. With load I mean the download time. Have a look at window.performance it contains all the timings. Also see html5rocks.

if (window.performance && window.performance.timing)
{
    var download_time = (window.performance.timing.responseEnd           - window.performance.timing.responseStart);
    var speed = ($('html').html().length) / download_time;
    if (speed < 400)
    {
        alert('slow');
    }
    else    {
        alert('fast');
    }
}

Note that this works best it the page size is large. For small pages the TCP/IP overhead for is large compared to your download time. My page was about 19304 bytes and I was able to detect mobile vs desktop.

Also see this stackoverflow question.

This does not work for IE8 and Safari

Montag, 16. Juni 2014

Bitbucket: Search file size to find big files

To find big files in your repository you can press F12 and search in your browser using the Bitbucket Api. Here is an example:
function getFolder(name){
 $.getJSON(name, function(response)
 { 
  $.each(response.directories, function(i, a)
  { 
   getFolder(name + '/' + a);
  } );
  $.each(response.files, function(i,a){ 
   if (a.size > 1024*1024 ) console.log(name, a);
  });
 });
}

getFolder('https://bitbucket.org/api/1.0/repositories/<user>/<rep-slug>/src/master/');

Montag, 5. Mai 2014

Nettes JavaScript Rätsel-Spiel

Links hat man eine 2D ASCII Welt in der man rumlaufen kann. Rechts ein JavaScript, dass die Welt generiert und steuert. Es gilt das Script an den erlaubten Stellen so zu ändern das man links zum Ausgang kommt: untrusted

Die 2D Welt basiert übrigens auf rot.js. Ein JavaScript Framework für 2D roguelike Spiele in ASCII Graphik. Mit Pathfinding, Lightning, Field of View (FOV) in einem Canvas. Schick!

Freitag, 15. Februar 2013

JavaScript "use strict";

In JavaScript gibt es einen strict mode, der hilft viele Fehler zu vermeiden. Leider unterstütz IE ihn erst ab Version 10, aber zum Entwickeln macht es Sinn ihn zu benutzen.

Mehr dazu: Stackoverflow Meinungen, MDN Doku, Verbreitung, Tutorial

Mittwoch, 2. Januar 2013

JavaScript Tutorial for Professionals

If you have used used JavaScript for some time you might want to have look at JavaScript-Garden. It's very helpful!

Mittwoch, 26. Oktober 2011

Howto use the Firebug console where every you are

console.log() does not work in most situations. A simple solution to debug everywhere is to use Firebuglite. Add this small Javascript it your page and your problems are solved. It detects if the console is available and adds it where needed.

Mittwoch, 10. August 2011

Online Javascript IDE

JSFiddle ist ein nettes Tool um Javascript zu entwickeln.
Besonders nett: Es lassen sich die gängigen Frameworks wie jQuery, extjs, Mootools, YUI, Processing, Dojo einbinden. Nützlich ist auch, wenn man mal Hilfe braucht, dass man einfach die URL weiterschicken kann. Auch Ajax Requests werden unterstützt.

Donnerstag, 10. Februar 2011

Javascript load from different domain

Because of the same origin policy you can not load Javascript from a different domain. However this only applies to AJAX requests. If you add a HTML script tag to a webside the browser loads and executes it:

javascript:(s=(d=document).createElement("script")).src="http://google.de"; void(d.body.appendChild(s))


With the "javascript:" in front, you can execute it on any webpage. Just copy it in your browsers address bar and press enter. With this you can add new features to other pages. A function to delete all entries from facebooks pinboard or studivz would be nice. To make it look nice, you can add your script as bookmarklet to your browsers bookmarks.

Donnerstag, 6. März 2008

Triple Quotation Mark

I would like to see a new feature which is useful in almost every programming language in which you like to generate HTML and JavaScript code. Beside the single quotation mark ' and the double quotation mark " a new triple quotation mark ''' would be very handy.

Why? See for example this php code:

echo '';

This common statement generates a HTML submit button with an onclick JavaScript event. By using the ' and " quotation marks it was already avoided to escape the quotation marks for the HTML code, but for the JavaScript it is still necessary to escape the alert message string with \'

Some people might say you can also use the PHP operator <? ?> to write the HTML directly without using the echo command, but if you work with objects it is often necessary to place the HTML code in a string.

In practice we have much more complex code lines as the simple example above, so it would be easier to read with a triple quotation mark:

echo ''''Done''');" type="submit">';

Just a funny idea of mine :)