spirit posteets tagged javascript  [ Profile ]

Sort by: Date / Title /

  1. 10 years ago
    When the location you want is in the center of the map, copy and paste this code into the location bar of your browser and press enter
    1. javascript:void(prompt('',gApplication.getMap().getCenter()));
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1412"></script>
  2. 10 years ago
    This little trick allows a Flash movie (swf) to find out the URL of the page in which it's embedded. Javascript must be enabled for this to work. if the window.location.href.toString method doesn't return a value then ExternalInterface.call will return null. Same thing happens when Javascript is disabled.
    1. // This little trick allows a Flash movie (swf) to find out the URL of the page in which it's embedded.
    2.  
    3. import flash.external.ExternalInterface;
    4.  
    5. var pageURL:String =
    6.         ExternalInterface.call('window.location.href.toString');
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1411"></script>
  3. 10 years ago
    if toFixed is not defined
    1. if (!num.toFixed)
    2. {
    3.  
    4.  Number.prototype.toFixed = function(precision) {
    5.      var power = Math.pow(10, precision || 0);
    6.      return String(Math.round(this * power)/power);
    7.  }
    8.  
    9. }
    10.  
    11. // OR
    12.  
    13.   Number.prototype.toFixed = function(precision)
    14.   {
    15.      var num = (Math.round(this*Math.pow(10,precision))).toString();
    16.      return num.substring(0,num.length-precision) + "." +
    17.             num.substring(num.length-precision, num.length);
    18.   }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1403"></script>
  4. sponsorised links
  5. 10 years ago
    1. anchor = window.location.hash;
    2. anchor = anchor.substring(1,anchor.length); // enleve le #
    3.  
    4. //-- Juste pour l'archivage, voici le code que j'utilisais avant de savoir qu'une fonction js existait
    5. var url = document.location.toString();
    6. if (myFile.match('#')) {
    7.     var anchor = myFile.split('#')[1];
    8. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1235"></script>
  6. 10 years ago
    1. // Le JS dans la div ci-dessous a été inséré par une requete AJAX
    2. // <div id='mydiv'> <script type='text/javascript'> [...] </script> </div>
    3.  
    4. var div = document.getElementById('mydiv');
    5. div.innerHTML = innerHTML;
    6. var x = div.getElementsByTagName("script");
    7. for(var i=0;i<x.length;i++)
    8. {
    9.        eval(x[i].text);
    10. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1207"></script>
  7. 11 years ago
    1. Remove the events from the options, use an event directly on the select instead.
    2.  
    3. function myfunc(value) {
    4.   alert(value);
    5. }
    6. ...
    7. <select onchange="myfunc(this.options[this.selectedIndex].value)">
    8.   <option value="1">Item1</option>
    9.   <option  value="2">Item2</option>
    10. </select>
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/761"></script>
  8. 11 years ago
    1. var myfunc = function(optional) {
    2.   if (typeof optional == "undefined") {
    3.     optional = "default value";
    4.   }
    5.   alert(optional);
    6. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/691"></script>
  9. 11 years ago
    1. $.create = function() {
    2.   var ret = [], a = arguments, i, e;
    3.   a = a[0].constructor == Array ? a[0] : a;
    4.   for(i=0; i<a.length; i++) {
    5.     if(a[i+1] && a[i+1].constructor == Object) { // item is element if attributes follow
    6.       e = document.createElement(a[i]);
    7.       $(e).attr(a[++i]); // apply attributes
    8.       if (a[i] == 'table') alert ('titi');
    9.       if(a[i+1] && a[i+1].constructor == Array) $(e).append($.create(a[++i])); // optional children
    10.       ret.push(e);
    11.     } else { // item is just a text node
    12.       ret.push(document.createTextNode(a[i]));
    13.     }
    14.   }
    15.  
    16.   return ret;
    17. };
    18.  
    19.  
    20. // Usage
    21. $.create(
    22.    'table', { 'class':"MyTable" }, [
    23.       'tbody', {}, [
    24.          'tr', { 'class':"MyTableRow" }, [
    25.             'td', { 'class':"MyTableCol1" }, [ "howdy" ],
    26.             'td', { 'class':"MyTableCol2" }, [
    27.                "Link:", 'a', { 'class':"MyLink", 'href':"http://www.example.com" }, ["example.com"] ] ],
    28.          'tr', { 'class':"MyTableRow2" }, [
    29.             'td', { 'class':"MyTableCol1" }, [ "howdy" ],
    30.             'td', { 'class':"MyTableCol2" }, [
    31.                "Link:", 'a', { 'class':"MyLink", 'href':"http://www.example.com" }, ["example.com"] ] ] ] ]);
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/115"></script>

First / Previous / Next / Last / Page 1 of 1 (8 posteets)