javascript Kopírování textu - zabránění
Jak zabránit kopírování textu stránky v prohlížeči.
Do tagu body vložíme následující eventy:
oncontextmenu="return false" onmousedown="return false" onselectstart="return false" ondragstart="return false"
Tag body by mohl vypadat následovně:
<body oncontextmenu="return false" onmousedown="return false" onselectstart="return false" ondragstart="return false">
77LW NO topic_id
AD
Další témata ....(Topics)
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
}
Jeden znak: a, b nebo c | [abc] | [abc] | a bb ccc |
Znak kromě: a, b nebo c | [^abc] | [^abc] | d, ff, mmm ale ne a, bb, ccc |
Znak od až po: a-z | [a-z] | [a-z] | jez, mez, bez ale ne keřík - neumí diakritiku |
Znak není v rozsahu: a-z | [^a-z] | vybere prázdné mezery i pismena s diakritikou | |
Znak v rozsahu: a-z nebo A-Z | [a-zA-Z] | neumí diakritiku | |
Jakýkoliv jednotlivý znak | . | bere vše i diakritiku, kromě znaku konce řádku | |
Znak mezery | \s | ^\r
\t\f\v a mezery | |
Znak není mezera | \S | vše kromě mezer viz výš | |
Číslice | \d | pouze číslice | |
Libovolné jiné než číslice | \D | vše výjma číslic | |
Jakýkoliv znak písmena | \w | \w+ | celá slova pokud neobsahují diakritku či nepísmena |
Jakýkoli znak jiný než písmeno | \W | \W+ | *-+#@ ale ne _ podtržítko |
Vše co bude v závorce (group) | (...) | (he) | všechna he ze slov |
Buď a nebo b | (a|b) | (a|b) | vybere vešechna a i b ze slov |
Nula nebo jeden znak a | a? | bao? | bao , ba, ale ne samotne b |
Nula nebo více | a* | bao* | ba, bao ale ne b, bax, bac |
Jeden nebo více | a+ | a až nekonečno aaaa i a uprostřed slova | |
Přesně 3 znaky a | a{3} | aaa aaaa jen první 3 znaky, ale ne aa | |
3 nebo více znaků a | a{3,} | aaa až nekonečno aaaaaaaa | |
Mezi 3 a 6 znaky a | a{3,6} | aaa aaaaaa ale ne aa | |
Začátek řetězce | ^ | ^\w+ | např. slovo je začátek nového řádku |
Konec řetězce | $ | \w+$ | (veme konci) poslední slovo na konci |
Hranice slova | \b | d\b | (veme d na konci slov) hrad led |
Není hranice slova | \B | a\B | a v ab, ale ne v ba |
Nový řádek |
| \r
?| | cross platform newline / nalezne nový řádek napříč platformami |
Tab - tabulátor | \t | ||
Carriage return CR | \r | návrat vozíku https://cs.wikipedia.org/wiki/Carriage_return | |
$country[0] = "cz"
$country[1] = "sk"
$country[2] = "de"
$country[3] = "uk"
$country[4] = "fr"
// this do same
$country[] = "cz"
$country[] = "sk"
$country[] = "de"
$country[] = "uk"
$country[] = "fr"
// or
$country = array('cz','sk','de','uk','fr');
// get array items count
$length = count($country);
for($i=0;$i<$length;$i++){
print $country[$i].'<br>';// cz sk de uk fr
}
// or like this
$country[50] = 'ca';
$country[10] = 'fr';
$country[20] = 'us'
// now country will index 51
$country[] = 'ru';
// or
$country = array('5'=>'cz','sk','de','uk','fr');
/*
Array
(
[5] => cz
[6] => sk
[7] => de
[8] => uk
[9] => fr
)
*/
// you can do this
$country["cz"] = 1571;
$country["sk"] = 1572;
$country["de"] = 1573;
$country["uk"] = 1574;
$country["fr"] = 1575;
print $country["uk"]; // 1574
// print all items key and value
foreach ($country as $key => $value){
print $key; // cz, sk, de, uk, fr
print $value; // 1571, 1572, 1573, 1574, 1575
}
Funkce JavaScript pro práci s datumem a časem.
function msToTime(duration) {
var milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;
return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
}
// console.log(msToTime(300000))
// output: 00:05:00.0
// get time difference between two dates in seconds
var startDate = new Date();
// Do your operations
var endDate = new Date();
var seconds = (endDate.getTime() - startDate.getTime()) / 1000;
var milliseconds = (endDate.getTime() - startDate.getTime());
[, OPTIONAL second param [, OPTIONAL ... param]]
static Date.now() // returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
parse(dateVal) // Date.parse('05 Dec 1998 00:12:00 GMT'); // return 912816720000
toDateString() // sunday 19.7.2020
toTimeString() // 20:15:37
getDate() // 1-31
getDay() // 0-6, 0 == Sunday
var now = new Date();
var dayOfWeekSundayIs7 = now.getDay() == 0)?7:now.getDay();
getFullYear() // 2020
getHours() // 0-23
getMilliseconds() // eg. 956
getMinutes() // 0-59
getMonth() // 0 january
getSeconds() // 0-59
getTime() // https://en.wikipedia.org/wiki/Unix_time
getTimezoneOffset() //returns the time zone difference, in minutes, from current locale
getYear() //does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the getFullYear() method.
setDate(numDate) // 1-31 day of month
setHours(numHours[, numMin[, numSec[, numMilli]]]) // now.setHours(20, 21, 22); 20:21:22
setMilliseconds(numMilli) // 0-999
setMinutes(numMinutes[, numSeconds[, numMilli]]) // 0-59, 0-59, 0-999
setMonth(numMonth[, dateVal]) // 0-11
setSeconds(numSeconds[, numMilli]) 0-59 [, 0-999]
setYear(numYear) // not set full years ("year 2000 problem"), it is no longer used and has been replaced by the setFullYear() method.
setUTCDate() //
setUTCFullYear(2020) // 2020 sets the full year for a specified date according to universal time GMT
setUTCHours()
setUTCMilliseconds()
setUTCMinutes()
setUTCMonth()
setUTCSeconds()
toLocaleTimeString()
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
now.toLocaleDateString(undefined, options); //neděle 19. července 2020
// PDT Pacific Daylight Time (UTC -7)
// GMT ... SET GMT TIME +- ZONE ... new Date('December 31, 1974 23:59:30 GMT-3:00');
toGMTString() // DEPRECATED!!!! use toUTCString()
// Using UTC instead GMT!!!
var d = new Date("2020-07-15T00:00:00.000+07:00"); // UTC + 7
console.log(d.toISOString()); // "2020-07-14T17:00:00.000Z"
console.log(d.valueOf()); // 1594746000000
toISOString() // "2020-07-14T17:00:00.000Z"
toJSON() // "2020-07-14T17:00:00.000Z"
toSource() //This feature is obsolete!!!! Dont use!!!!
toString() // "Tue Jul 14 2020 19:00:00 GMT+0200 (Středoevropský letní čas)"
toUTCString() // "Tue, 14 Jul 2020 17:00:00 GMT"
valueOf() // 1594746000000
Jak pomocí javascript odeslat či přijmout data na/ze serveru
// volani funkce s adresou php stranky kde pomoci $_GET["data1"] a $_GET["data2"] vyjmeme
// zaslana data v url a ulozime na serveru
// zpet muzeme ziskat hlaseni zda operace probehla v poradku
httpGet("http://www.myweb.com/save_get_data.php?data1=hello&data2=someText");
function httpGet(theUrl)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
createDiv(xmlhttp.responseText);
}
}
xmlhttp.open("GET", theUrl, false);
xmlhttp.send();
}
// zobrazi text php stranky zda vse probehlo v poradku, pokud si v php scriptu nastavim echo
// s textem ze operace pobehla ok nebo ne pak v _div se objevi toto hlašení
function createDiv(responsetext)
{
var _body = document.getElementsByTagName("body")[0];
var _div = document.createElement("div");
_div.innerHTML = responsetext;
_body.appendChild(_div);
}
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:javascript-kopirovani-textu-zabraneni