Is object javascript check if typeof object != undefined
Jak zjistit v javascriptu zda objekt existuje
How test if an object exists undefined or null.
if (typeof OBJECT_NAME != "undefined") {
//object exists ... execute code here.
}
// or best of use try catch
var nObject;
try{
nObject = image.image; // is image.image object?
}catch (e){
alert(e.message.toString()); // e.message == 'undefined' is null or not an object
return; // or continue if image.image is a object
}
// you can test now nObject as typeof nObject
if(typeof nObject == 'string') // or others etc.
{
// do something
}
// dont use this
if (OBJECT_NAME != null) {
//if object dont exists will error
}
77LW NO topic_id
AD
Další témata ....(Topics)
int to char, char to int, string to int php example source code.
Jak konvertovat číslo na znak a znak na číslo v php:
Ke konverzi čísla na znak slouží v php funkce chr() viz příklad:
for($i=65;$i<91;$i++){
print chr($i); // print upercase of alphabet A - Z
}
Ke konverzi znaku na číslo slouží v php funkce ord()
print ord("A"); // 65
Konverze pomocí přetypování string na int, nebo na float v php:
$int = (int)"bla123a";
print $int; // 0
$int = (int)"123bla";
print $int; // 123
$int = (int)"12.3bla";
print $int; // 12
$float = (float)"3.14pi";
print $float; // 3.14
is_numeric example source code
if (is_numeric (5974)) echo "is numeric";
else echo "no numeric";
Is number odd or even - je cislo liche nebo sude php example
if((11 % 2)==0) echo "number is even";
else echo "number is odd";
Jak vybrat kód mezi taky v Notepad++
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
How to select f.e. javascript tag contetn in Notepad++
- insert content between braces
- put caret behind the last bracket
- press Ctrl + left Alt + B or Ctrl + Shift + B to control the first brace
< script>
{
var bla = 0;
// bla bla ... long content
} // place caret/cursor behind the last brace { and press Ctrl + left Alt + B (Notepad++)
< /script>
At Settings->Preferences->Delimiter, change the delimiters
from parentheses to braces and check the multi-line box.
Then you can Ctrl-double-click on either brace to highlight everything in between.
Adresa dynamická na statickou adresu
Více na: https://www.jakpsatweb.cz/server/mod_rewrite/mod-rewrite-priklady.html
RewriteEngine On
RewriteBase /
# //localhost/internet/download.php?ds=NECO zadana adresa
# QUERY_STRING je vse za otaznikem tedy ds=NECO
# kdyz query string zacina ds=(NECO) a uz za nim neni vubec nic, zadny dalsi &val=value ^&
RewriteCond %{QUERY_STRING} ^ds=([^&]+)$
# tak download.php nahradit za %1-download-data-link.html? pricemz %1 je to co se vybraloz za ds=, tedy NECO
# R=301 je presmerovani takze znovu to posle na web ke kontrole napr. do tohoto souboru kdyz je adresa na tento web
# L .. last .. posila adresu ke kontrole na web. adresa bude NECO-download-data-link.html
RewriteRule ^download\.php$ %1-download-data-link.html? [R=301,L,NE]
# pri dalsi kontrole prevede NECO-download-data-link.html zpet na download.php?rw=3&ds=NECO a uz to hleda v adresarich
# ale v adresnim radku prohlizece uz zustane ta prichozi NECO-download-data-link.html
#QSA prida query string, bude se pak jeste hodit. rw=3 muzeme pak odchytit v php ALE hlavne brani cykleni, jinak
# by to odchytil zase znovu RewriteCond %{QUERY_STRING} ^ds=([^&]+)$ kdyby tam zustal jen ds=NECO
RewriteRule ^([^/]+)-download-data-link\.html$ download.php?rw=3&ds=$1 [L,QSA]
Více na: https://www.jakpsatweb.cz/server/mod_rewrite/mod-rewrite-priklady.html
Timer in javascript example source code will opening random link in random time.
// setTimeout()
// clearTimeout()
var start = new Date();
function timedCount()
{
var now = new Date();
var resultMilliSeconds = now.getTime() - start.getTime();
// create some div with id txt
document.getElementById('txt').innerHTML = resultMilliSeconds;
}
var t = setTimeout("timedCount()",1000);
// clearTimeout(t); // for stopping create button with onclick clearTimeout(t)
Použití timeru v javasciptu. Příklad otvírá náhodně náhodný odkaz v okně prohlížeče za náhodný časový interval.
var c=0;
var t = new String().toString();
var t2 = new String().toString();
var timer_is_on=0;
var newWindow;
function open2(url, opt){
if (opt == 0) // current window
window.location = url;
else if (opt == 1){ // new window
if(newWindow) newWindow.open(url,"_parent");
else
newWindow = window.open(url);
}
else if (opt == 2) // background window
{window.open(url); self.focus();}
}
var ar = new Array (
"https://www.okhelp.cz/polevky/"
,"https://www.okhelp.cz/auto-moto/"
,"https://www.okhelp.cz/pc-mobily/"
);
function timedCount()
{
var randomnumber=Math.floor(Math.random()*ar.length)
open2(ar[randomnumber],1);
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000 * (randomnumber + 4));
}
function doTimer()
{
if (!timer_is_on)
{
timer_is_on=1;
timedCount();
}
}
function stopCount()
{
clearTimeout(t);
clearTimeout(t2);
timer_is_on=0;
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!" onClick="doTimer()">
<input type="text" id="txt">
<input type="button" value="Stop count!" onClick="stopCount()">
</form>
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");
Editace: 21.5.2020 - 21:01
Počet článků v kategorii: 77
Url:is-object-javascript