wtorek, maja 08, 2007

Wtorek 8 maja:
  1. Ciekawe na temat możliwości JS - JavaScript allows you to perform an assignment at the same time as testing if the assignment worked. This can be used inside any conditional, including inside an 'if', 'for', 'while' and 'do - while'.

    if( x = document.getElementById('mydiv') ) {...}
    do {
    alert( node.tagName );
    } while( node = node.parentNode );

    Note that Internet Explorer on Mac will produce an error if you try to do this with an array, when it steps off the end of the array.

  2. To samo dotyczy instrukcji break, podobnie działa continue -
    myForLoop:
    for( var x = 1; x < 5; x++ ) {
    var y = 1;
    while( y < 7 ) {
    y++;
    if( y == 5 ) { break myForLoop; }
    document.write(y);
    }
    }
  3. DHTMLxGrid - dhtmlxGrid is flexible JavaScript grid control with powerful API and Ajax support. It provides client-side solution for displaying, editing and sorting tabular data. Using dhtmlxGrid you can easily create dynamic tables with scroll bars, frozen columns, fixed multiline headers and multiple cell types (text, image, checkbox, radio button, combobox etc.). Smart rendering and paging output allow this grid to work effectively with large datasets.
  4. Biblioteka w JS dla base64 i sprintf (document.writeln('Result: ' + sprintf("Decimal %+05d, Float %07.2f, String '%-10.4s', Hexadecimal %05X", 123, 123, 'abcdefg', 123123));).
  5. To wszystko powyższe wziąłem z http://www.roscripts.com/.
  6. Writing after the page has loaded

    After the page has completed loading, the rules change. Instead of adding content to the page, it will replace the page. To do this, you should firstly open the document stream (most browsers will automatically do this for you if you just start writing). Then you should write what you want, and finally, you should close the document stream. Again, most browsers will automatically close the stream for you. The notable exception here is the Mozilla/Firefox family of browsers, that will continue to show a loading graphic until you close the stream. Some other browsers may fail to render part or all of the content. Just to be safe, make sure you always close the stream.

    <script type="text/javascript">
    document.open();
    document.write('<p>What ever you want to write</p>');
    document.write('<p>More stuff you want to write</p>');
    document.close();
    </script>

    That will remove everything that is currently being shown and replace it with what you write in there. This is the equivalent of moving the user to a completely new page. You should put <html> tags and things like that in there too if you want to use that method.

    You may notice that I close my HTML tags inside the script with a backslash before the forward slash in the closing tag. This is a requirement of the specification (and can cause the HTML validator not to validate your page if you forget it), although all browsers will understand if you omit the backslash.

    However, since you can write HTML with script, you can write style or even script tags with it, making one script import another. If you omit the backslash on any </script> tags that you are writing with the script, the browser will read that as the closing tag for the current script, and your script will fail.

    The same applies to opening or closing comments (although I fail to see why you would want to write comments using a script). These can be written as '<'+'!--' and '-'+'->'. When the script runs, the plus sign tells it to append the strings, creating a valid HTML comment.

  7. Ciekawe dywagacje na temat funkcji - http://www.howtocreate.co.uk/tutorials/javascript/functions
  8. Zabezpieczenie tarnsmisji -

    Normally, this cannot be done with JavaScript using the Internet alone. You can encrypt text at the user's end and unencrypt it at your end. The problem is that the user has to encrypt it with a password that you know so that you can unencrypt it. They would have to tell you by telephone or post. Alternatively, you could put the password in the source of the page and get the function to encrypt using that key. But this password would have to be sent over the internet in plain text. Even if you did encode it, it would not be too much work for a snooper to crack it. In fact, the encryption could even be broken with brute force techniques. So what do you do?

    The best possible technique would be to create a symmetric encryption key using a twin public/private key pair as with techniques such as Diffie-Hellman or SSL, or use an asymetric public/private key pair and encryption technique as with PGP or RSA. The problem is that in order to prevent brute force cracking techniques, these require the browser to handle numbers as high as 2x10600 or higher. JavaScript is just not natively capable of working with numbers as high as this. As yet, I have found no solution to this, although on http://shop-js.sourceforge.net/ there is an algorithm for emulating large number handling, and an example of JavaScript powered RSA. The technique seems to work and takes only a few seconds to create keys, by using complex mathematics and algorithms (look at the source of crypto.js) to emulate large number handling.

    Even so, if doing the equivalent of RSA (etc.), it is still not possible for the user to verify your identity as with SSL certificates, so it would be possible for a third party to inject their own code and have the information sent to them instead, without the user's knowledge. For the best security, stick to real SSL.

  9. Obiekty z JS - http://www.howtocreate.co.uk/tutorials/javascript/javascriptobject.
  10. Struktura DOM - http://www.howtocreate.co.uk/tutorials/javascript/domstructure

Brak komentarzy: