Function exist javascript if typeof variable == function
Kontrola v javascript zda funkce existuje
Check if a Javascript Function Exists or Is Defined.
function myFunctionName() {
alert('I am myFunctionName');
}
if (typeof myFunctionName == 'function') {
myFunctionName();
}
77LW NO topic_id
AD
Další témata ....(Topics)
HTML TAGS EXAPLES
ANCHOR:
<a href="#bla">bla target</a>
invisible target
<a name="bla">bla</a>
OR visible target
<h2 id="bla"></h2>
JavaScript
var elmnt = document.getElementById("bla");
elmnt.scrollIntoView();
Invisible hidden collabsible toggle switch DIV
<div id="idDiv">Hello</div>
// javascript button onclick
if(show){
idDiv.style.display === "block";
}else{
idDiv.style.display = "none";
}
Date: 16.07.2020 - 10:27
HTTP to HTTPS
# only one RewriteEngine On can be used in htaccess!!!!!!!!!!!!!!
RewriteEngine On
# all redirection HTTP -> HTTPS
# HTTPS off / if start with http.....
# off equality !=on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
example.com to www.example.com
# redirection no www -> https://www.
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Change sitemap.txt to sitemap.php if url //domain.com/sitemap.txt
# //domain.com/sitemap.txt open sitemap.php
# in sitemap.php is function what return list of address
RewriteRule ^sitemap\.txt$ sitemap.php [L]
RewriteRule ^sitemap$ sitemap.php [L]
Remove www. before subdomain name
www.subdomain.example.comto
subdomain.example.com
RewriteCond %{HTTP_HOST} (^|\.)(www\.)([^\.]*)\.example\.com$ [NC]
RewriteRule (.*) https://%3.example.com/$1 [R=301,QSA,L]
Remove dust before subdomain.example.com
# www.bla.www.m.bla.subdomain.example.com to subdomain.example.com
RewriteCond %{HTTP_HOST} (.*)(subdomain.example.com$) [NC]
RewriteRule (.*) https://subdomain.example.com/$1 [R=301,QSA,L]
Remove only one www. before domain name
# redirection www. -> https://
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Odkazy na online regex editory:
https://regex101.com/
https://www.debuggex.com/r/LyIpMYTAhJ9Gja4x
https://regex101.com/
https://www.debuggex.com/r/LyIpMYTAhJ9Gja4x
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>
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>
Editace: 21.5.2020 - 20:58
Počet článků v kategorii: 77
Url:function-exist-javascript