javascript check if page correctly loaded
Příklad vychází z předpokladu, že těsně před konečným
tagem /BODY je kontejner tag s názvem < footer>< /footer>.
Mezeru < TAGNAME nutno odstranit v reálném kódu.
Pokud tento tag je nalezen, lze předpokládat, že uživatel
stránku již uvidí celou, protože většina prohlížečů si s
tím poradí a doplní chybějící uzavírací tagy BODY a HTML.
// < TAGNAME remove space after < !!!!!
< BODY onload="myFunction">
< sript>
function myFunction() {
var x = document.getElementsByTagName ("footer");
if(x.length === 0)
alert("Page not loaded correctly ... not find tag footer x" + x);
else
alert("Heureka! :) FOOTER is loaded!");
}
< /script>
77LW NO topic_id
AD
Další témata ....(Topics)
Letní čas tak připočítat hodinu.
Ověření zda je letní čas.
$dst = date("I"); //I (capital i); 0 or 1 if daylight saving time
// example:
$hour = 14;
if(date("I")===1){
$hour = $hour + 1;
}
// OR
$hour = 14 + date("I");
Jak vytvořit slovník podstatných jmen.
Velmi snadno. Stačí si stáhnout slovník pro kontrolu pravopisudo Open Office org a tam již druhy slov májí za lomítkem určující znaky.
//wiki.services.openoffice.org/wiki/Dictionaries#Czech_.28Czech_Republic.29
Ukázka obsahu slovníku:
alokuce/Zalokující/YN
alokátor/H
alolex/H
alomorf/H
aloový/YKRN
aloparentální/YKR
alopatický/YCRN
alopatie/Z
Dodržujte licence slovníků
Některé funkce pracující s polem v JavaScriptu
var myArray = []; // smazat obsah, nebo inicializovat nove pole
concat([item1[, item2[, . . . [, itemN]]]])
concat([string2[, string3[, . . . [, stringN]]]])
/* spoji stringy nebo pole a vraci novy string nebo pole */
join(separator)
/* vrati v string spojene itemy poli oddelene separatorem*/
push([item1 [item2 [. . . [itemN ]]]])
/* prida na konec pole novy item a vraci delku pole*/
pop()
/* odebere posledni element z pole a vrati jeho hodnotu*/
reverse()
/*vraci obracene poradi itemu pole*/
shift()
/* odebere prvni item z pole a vrati jej*/
slice(start, [end])
/* varaci cast pole*/
var numArray = new Array(3,2,5,9);
var newNumArray = numArray.slice(1,3); // 2,5
sort() // string
sort(sortFunction)
/* setridi pole cisel od nejvetsiho - descending */
sort(function(a, b){return b-a})
/* setridi od nejmensiho cisla - ascendant*/
sort(function(a, b){return a-b})
splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])
/* odebere element z pole, popripade vlozi novy a vrati odebrany element*/
var numArray = new Array(3,2,5,9);
var newNumArray = numArray.splice(1,1); // 3,5,9
unshift([item1[, item2 [, . . . [, itemN]]]])
/* prida na pocatek item, ktery je parametrem funkce */
var myA = new Array(10,11,12);
myA.unshift(1); // 1,10,11,12
List of usefull JavaSript functions and constans
var 1_radian_to_degree = 180 / Math.PI; // 57,295779513082320876798154814105 degree
var 1_degree_to_radian = Math.PI / 180; // 0,01745329251994329576923690768489 radian
var 360_degree = 2 * Math.PI * 1_radian_to_degree;
parseInt("10.33") // returns 10 string to integer
parseFloat("10.33") // returns 10.33 string to float
// change sign
var a = -1;
a = a * -1; // +1
// random sign
a *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
var who_is = 58;
var type = (typeof who_is); // number
Math.E // natural logarithms, e, approximately 2.718281828459045
Math.LN10 // natural logarithm of 10, approximately 2.302585092994046
Math.LN2 // natural logarithm of 2, approximately 0.6931471805599453
Math.PI // approximately 3.141592653589793
Math.SQRT1_2 // square root of 1/2 which is approximately 0.7071067811865476
Math.SQRT2 // square root of 2, approximately 1.4142135623730951
Math.pow(4, 2) = 16 // 4 x 4 ... base 4 to the exponent 2 power
Math.abs(-5) absolute value of a number // return 5
Math.tan(degrees * Math.PI / 180) // get tangent from degrees
Math.tan(degree * Math.PI / 180)*adjacent = opposite
opposite / Math.tan(degree * Math.PI / 180) = adjacent
Math.acos(adjacent / hypotenuse) // angle of a right-angle triangle in radians
Math.atan(opposite / adjacent) // angle of a right-angle triangle in radians
var adjacent = Math.cos(radian) * hypotenuse; // leng of adjacent side
// find the point on a circle if you know the circle´s radius
var x = Math.cos(pointAngleInRadiansFromCentreOfCircle) * radius;
var y = Math.sin(pointAngleInRadiansFromCentreOfCircle) * radius;
Math.cbrt(64) // cube root of a number 4 (4 x 4 x 4)
Math.exp(xNumber) // returns e<sup>xNumber</sup> ... e == Math.E
Math.ceil() // always rounds a number up to the next largest integer
Math.ceil(1.001) // 2
Math.floor() // returns largest integer less than or equal to a given number
Math.floor(5.85) = 5
Math.floor(-5.15) = -6
const arrayA = [2, 3, 1];
Math.min(...arrayA) = 1;
Math.max(1, 3, 2) = 3;
Math.random() // returns 0.000.... - 0.99999999999
Math.random() * 3 // returns 0.000 - 2.99999999999
Math.round() // returns value of a number rounded to the nearest integer.
Math.round(0.9) // 1
Math.round(5.5) // 6
Math.round(5.05) // 5
Math.floor(Math.random() * 3) // returns 0, 1, 2
Date: 14.06.2020 - 08:38Jak naformátovat číslo například 1000 aby výstup byl 1 000.
How formatting Numbers in javascript
// in us return 1,000.00 in czech cz return 1 000,00
var newNumber = format_Of_Number ('cz', 1000.00); // cz is czech format - us is us format of number
function format_Of_Number (stat, num) {
stat = stat.toLowerCase();
nStr = this + '';
var x = nStr.split('.');
var x1 = x[0];
var x2;
if(stat=='cz')
x2 = x.length > 1 ? ',' + x[1] : ''; // nahradime tecku carkou
else if(stat=='us')
x2 = x.length > 1 ? '.' + x[1] : ''; // us format
var rgx = /(d+)(d{3})/;
while (rgx.test(x1)) {
if(stat=='cz')
x1 = x1.replace(rgx, '$1' + ' ' + '$2'); // nahradime mezerou cesky format 1 000,00
else if(stat=='us')
x1 = x1.replace(rgx, '$1' + ',' + '$2'); // us format 1,000.00
}
return x1 + x2;
}
Editace: 18.5.2020 - 10:15
Počet článků v kategorii: 77
Url:javascript-check-if-page-correctly-loaded