The Wayback Machine - https://web.archive.org/web/20070514101139/http://mpulko.tripod.com:80/js/
mpulko.tripod.com

Menu

Programi/download
· MooLAN
· Alifatske spojine
· FileSplit
· Anketa
· Aditivi E

Tutoriali/primeri
· C++
· JavaScript
· Linux in bash skripte
· VBA makri
· Shockwave igre
· java
· pascal/delphi
· php
· Hacking

Igre
· Kviz
· Ladjice
· IQ test
· Barvni test

Povezave/linki
· Linux
· VBA makri
· Povezave name
· wappy.to/mpulko

· Domov


JavaScript

"; okno=window.open("","","scrollbars=0, toolbar=0, status=0, menubar=0, rezisable=0, location=0, directories=0, width=200, height=100"); okno.document.write(ss); okno.document.close(); } function popup2() { okno=window.open("index.htm","okno","scrollbars=1, toolbar=1, status=1, menubar=0, rezisable=0, location=1, directories=0, width=400, height=300"); okno.document.close(); } // ******************* function izberi() { if (document.F7.R1[0].checked) {window.status="prva"}; if (document.F7.R1[1].checked) {window.status="druga"}; if (document.F7.R1[2].checked) {window.status="tretja"}; } // ******************* var j=0; var t1; function timer() { j++; document.F8.T1.value=j; t1=setTimeout('timer()',1000); } function timer1() { clearTimeout(t1); } // ******************* function tiskaj() { window.print(); } // ******************* function nazaj() { history.go(-1); } // ******************* var datum1 = new Date(); //danasnji datum var datum2 = new Date(datum1.getTime() + 30 * 24 * 60 * 60 * 1000); // danasnji datum + 30 dni function setCookie(ime, value) { if (value != null && value != "") document.cookie=ime+"="+escape(value)+"; expires="+datum2.toGMTString(); } function getCookie(ime) { if (document.cookie.length>0) { var index = document.cookie.indexOf(ime+"="); if (index == -1) return null; index = document.cookie.indexOf("=", index) + 1; var endstr = document.cookie.indexOf(";", index); if (endstr == -1) endstr = document.cookie.length; alert (unescape(document.cookie.substring(index, endstr))); } } // -->

Kaj je JavaScript?
  • JavaScript je skriptni jezik za spletne strani.
  • Skripte napisane v JavaScriptu vključimo direktno v HTML dokument.
  • Sintaksa ukazov JavaScripta je podobna jeziku C++
Obika zapisa: <script language="JavaScript"><!--
ukaz1; ukaz2; ukaz3;
// --></script>

JavaScript koda se lahko nahaja tudi v posebni datoteki - ta se med izvajanjem avtomatsko vključi v spletno stran
<SCRIPT SRC="koda.js"> </SCRIPT>


1. Pošiljanje e-pošte iz domače strani:

 

<form action="mailto:[email protected]" method="post" enctype="text/plain" name="F1">
<textarea name="S1" rows="3" cols="30"> </textarea><br>
<input type="submit" name="B1" value="Poslji">
<input type="reset" name="B2" value="Zbriši">
</form>

2. Stran zaščitena z geslom (simple varianta):

 

function geslo()
{
var s;
s=document.F2.T1.value;
if (s=="pravo")
{ document.location="http://mpulko.tripod.com"; }
else
{ alert ("napacno geslo"); }
}

<input type="button" name="B1" value="OK" onclick="geslo()">

 

3. Pretvorba inčev v cm:

inč= cm

 

function pretvori()
{
var x, y;
x=parseFloat(document.F3.T1.value);
y=x/2.54;
document.F3.T2.value=y;
}
<input type="button" name="B1" value="Pretvori" onclick="pretvori()">

 

4. Spreminjanje slik

var slika1=new Image();
var slika2=new Image();
slika1.src="smile.gif";
slika2.src="vprasaj.gif";

<a href="javascript:alert('Alo');" onmouseover="document.S1.src=slika2.src;" onmouseout="document.S1.src=slika1.src;"> <img src="smile.gif" border="0" name="S1"> </a>

 

5. Kocka - naključna števila

 

function kocka()
{
var x;
x=parseInt(1+6*Math.random());
document.F4.T1.disabled=1;
document.F4.T1.value=x;
}

<input type="button" name="B1" value="OK" onclick="kocka()">

 

6. Barva ozadja

ugasni luč prižgi luč

 

function prizgi()
{
document.bgColor='white';
}

function ugasni()
{
document.bgColor='black';
}

<input type="radio" name="R1" value="V1" onclick="ugasni()">
<input type="radio" checked name="R1" value="V2" onclick="prizgi()">

 

7. Tabela (Array)

 

function tabela()
{
var a=new Array(3);
for (var i=0; i<3; i++)
{ a[i]=parseInt(prompt("vnesi "+i+" stevilo: ","")); }
for (i=0; i<3; i++)
{ document.F6.S1.value+=a[i]+"\n"; }
}

<input type="button" name="B1" value="Start" onclick="tabela()">

 

8. Dodaj med priljubljene (Bookmark)

 

function bookmark()
{
window.external.AddFavorite(this.location.href,this.document.title);
}

<input type="button" name="B1" value="Bookmark" onclick="bookmark()">

 

9. Novo okno (pop up window)

 

function popup1()
{
var t=new Date();
var ss="<HEAD><TITLE>Vaja</TITLE></HEAD><BODY><FONT size='6' color='red'>"+t.getTime()+"</FONT></BODY>";
okno=window.open("","","scrollbars=0, toolbar=0, status=0, menubar=0, rezisable=0, location=0, directories=0, width=200, height=100");
okno.document.write(ss);
okno.document.close();
}

function popup2()
{
okno=window.open("index.htm","okno","scrollbars=1, toolbar=1, status=1, menubar=0, rezisable=0, location=1, directories=0, width=400, height=300");
okno.document.close();
}

<input type="button" name="B1" value="popup1" onclick="popup1()">
<input type="button" name="B2" value="popup2" onclick="popup2()">

 

10. Radio buttons

a b c

 

function izberi()
{
if (document.F7.R1[0].checked) {window.status="prva"};
if (document.F7.R1[1].checked) {window.status="druga"};
if (document.F7.R1[2].checked) {window.status="tretja"};
}

<input type="button" name="B1" value="OK" onclick="izberi()">

 

11. Timer

sekund

 

var j=0;
var t1;
function timer()
{
j++;
document.F8.T1.value=j;
t1=setTimeout('timer()',1000);
}

function timer1()
{
clearTimeout(t1);
}

<input type="button" name="B1" value="Start" onclick="timer()">
<input type="button" name="B2" value="Stop" onclick="timer1()">

 

12. Natisni okno (Print)

 

function tiskaj()
{
window.print();
}

<input type="button" name="B1" value="Print" onclick="tiskaj()">

 

13. Skok na predhodno stran

 

function nazaj()
{
history.go(-1);
}

<input type="button" name="B1" value="Nazaj" onclick="nazaj()">

 

14. Stran je bila narejena:

Stran je bila narejena: <script language="JavaScript">
<!--
document.write(document.lastModified);
// --></script>

 

15. Cookies
(datoteka z nekim podatkom, ki se shrani na računalnik obiskovalca spletne strani)

 

var datum1 = new Date(); //danasnji datum
var datum2 = new Date(datum1.getTime() +
30 * 24 * 60 * 60 * 1000); // danasnji datum + 30 dni

function setCookie(
ime, value)
{
if (value != null && value != "")
document.cookie = ime + "="+escape(value) + "; expires=" + datum2.toGMTString();
}

function getCookie(
ime)
{
if (document.cookie.length>0)
{
var index = document.cookie.indexOf(ime+"=");
if (index == -1) return null; // Cookie ne obstaja
index = document.cookie.indexOf("=", index) + 1;
var endstr = document.cookie.indexOf(";", index);
if (endstr == -1) endstr = document.cookie.length;
alert (unescape(document.cookie.substring(index, endstr)));
}
}

<input type="button" name="B1" value="Pošlji Cookie" onclick="setCookie('mpulko','1')">
<input type="button" name="B2" value="Preberi Cookie" onclick="getCookie('
mpulko')">

 

for zanka

var s = 0;
for (var i=0; i < 10; i++)
{
s += i;
if (s > 50) break; // izhod iz zanke
}

while zanke

var s = 0;
while ( i< 10)
{
i++;
s+=i;
if (s > 50) break; // izhod iz zanke
}

Dogodki (Events):

na obrazcih (forms)
onFocus
- an event is triggered with a form object gets input focus (the insertion point is clicked there)
onBlur - an event is triggered with a form object loses input focus (the insertion point is clicked out of there)
onChange - an event is triggered when a new item is selected in a list box. This event is also trigged with a text or text area box loses focus and the contents of the box has changed
onSelect - an event is triggered when text in a text or text area box is selected
onSubmit - an event is triggered when the form is submitted to the server
onClick - an event is triggered when button is clicked

na dokumentu (document)
onLoad
- <body onload="go()">
onUnload - <body onunload="go()">

Lastnosti:

focus() - Equivalent to clicking this field document.F1.T1.focus();
blur() - Equivalent to clicking another field after using this one
select() - Equivalent to dragging the mouse across all the text in this field-selecting it
submit() - Equivalent to click Submit button document.F1.submit();

Več o JavaScriptu: http://zaversnik.fmf.uni-lj.si/Gradiva/JavaScript