Joel Luis Posted June 19, 2012 Report Share Posted June 19, 2012 Boas, Estou a iniciar a aprendizagem e gostava de saber como meter um script em javaScript numa página html. Podem-me explicar sff? Obrigado Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 se queres tuturiais para web based vai ao w3schools pagina de javascript http://www.w3schools.com/js/default.asp Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 Tipo eu tenho o ficheiro .js e quero usar o script que está lá dentro na página html Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 "let me use use google for you" http://lmgtfy.com/?q=load+javascript+file Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 eu tento e nunca dá... Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 mete aqui o codigo que estas a usar Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 (edited) HTML: <body background="back.jpg"> <script language="JavaScript" SRC="snow.js"> </script> ........... JAVA <!-- Coded by: JOEL LUIS --> <script> // Set the number of snowflakes (more than 30 - 40 not recommended) var snowmax=35 // Set the colors for the snow. Add as many colors as you like var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD") // Set the fonts, that create the snowflakes. Add as many fonts as you like var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS") // Set the letter that creates your snowflake (recommended:*) var snowletter="*" // Set the speed of sinking (recommended values range from 0.3 to 2) var sinkspeed=0.6 // Set the maximal-size of your snowflaxes var snowmaxsize=22 // Set the minimal-size of your snowflaxes var snowminsize=8 // Set the snowing-zone // Set 1 for all-over-snowing, set 2 for left-side-snowing // Set 3 for center-snowing, set 4 for right-side-snowing var snowingzone=3 /////////////////////////////////////////////////////////////////////////// // CONFIGURATION ENDS HERE /////////////////////////////////////////////////////////////////////////// // Do not edit below this line var snow=new Array() var marginbottom var marginright var timer var i_snow=0 var x_mv=new Array(); var crds=new Array(); var lftrght=new Array(); var browserinfos=navigator.userAgent var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/) var ns6=document.getElementById&&!document.all var opera=browserinfos.match(/Opera/) var browserok=ie5||ns6||opera function randommaker(range) { rand=Math.floor(range*Math.random()) return rand } function initsnow() { if (ie5 || opera) { marginbottom = document.body.clientHeight marginright = document.body.clientWidth } else if (ns6) { marginbottom = window.innerHeight marginright = window.innerWidth } var snowsizerange=snowmaxsize-snowminsize for (i=0;i<=snowmax;i++) { crds[i] = 0; lftrght[i] = Math.random()*15; x_mv[i] = 0.03 + Math.random()/10; snow[i]=document.getElementById("s"+i) snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)] snow[i].size=randommaker(snowsizerange)+snowminsize snow[i].style.fontSize=snow[i].size snow[i].style.color=snowcolor[randommaker(snowcolor.length)] snow[i].sink=sinkspeed*snow[i].size/5 if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)} if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)} if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4} if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2} snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size) snow[i].style.left=snow[i].posx snow[i].style.top=snow[i].posy } movesnow() } function movesnow() { for (i=0;i<=snowmax;i++) { crds[i] += x_mv[i]; snow[i].posy+=snow[i].sink snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]); snow[i].style.top=snow[i].posy if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){ if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)} if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)} if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4} if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2} snow[i].posy=0 } } var timer=setTimeout("movesnow()",50) } for (i=0;i<=snowmax;i++) { document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>") } if (browserok) { window.onload=initsnow } </script> <font face="Tahoma"><a target="_blank" href="http://www.swaggerstv.filipemacau.com"><span style="font-size: 8pt; text-decoration: none">JavaScript Free Code</span></a></font> Edited June 19, 2012 by Joel Luis Link to comment Share on other sites More sharing options...
softklin Posted June 19, 2012 Report Share Posted June 19, 2012 Para o fazeres, basta colocares no teu documento a seguinte instrução: <script type="text/javascript" src="caminho/para/o/ficheiro.js"></script> O facto de não estares a conseguir pode ter a ver com questões de caminhos. Estás a usar um ficheiro que está fora do teu site? Neste caso deves colocar todo o URL, incluindo http:// ... . Se estiveres a usar um ficheiro no teu site, podes também indicar o caminho nesta forma, ou sob a forma de caminho relativos, tal como estás a fazer agora. Neste caso, tens de te certificar que o ficheiro snow.js está na mesma pasta que o ficheiro html. Espreita também a consola de erros do teu browser para ver se não é o script que tem erros, causando a interrupção da execução. Nick antigo: softclean | Tens um projeto? | Wiki P@P Ajuda a comunidade! Se encontrares algo de errado, usa a opção "Denunciar" por baixo de cada post. Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 Para o fazeres, basta colocares no teu documento a seguinte instrução: <script type="text/javascript" src="caminho/para/o/ficheiro.js"></script> O facto de não estares a conseguir pode ter a ver com questões de caminhos. Estás a usar um ficheiro que está fora do teu site? Neste caso deves colocar todo o URL, incluindo http:// ... . Se estiveres a usar um ficheiro no teu site, podes também indicar o caminho nesta forma, ou sob a forma de caminho relativos, tal como estás a fazer agora. Neste caso, tens de te certificar que o ficheiro snow.js está na mesma pasta que o ficheiro html. Espreita também a consola de erros do teu browser para ver se não é o script que tem erros, causando a interrupção da execução. Sim esta na mesma pasta do meu site, mas eu tenho no pc. Ainda nao tenho em nenhum alojamento Obrigado Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 usa o browser e mete no codigo fonte da pagina, vais a essa linha de codigo e clicas onde diz: "snow.js", e se te aparecer o teu ficheiro, entao e' problemas de codigo, senao e' problemas dos caminhos. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 Yah aparece.... estão os 2 bem Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 mete um alert("alguma coisa"); no meio do ficheiro js. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 mete um alert("alguma coisa"); no meio do ficheiro js. Nao faz nada 😞 Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 entao nao faz os 2, tens um erro no codigo do javascript! Se o corrigires, teoricamente o problema fica resolvido. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
Joel Luis Posted June 19, 2012 Author Report Share Posted June 19, 2012 nao é erro do java tambem nao, e tipo um calendario em java para usar na pagina e dps meter onde quiser isso dá? Link to comment Share on other sites More sharing options...
pikax Posted June 19, 2012 Report Share Posted June 19, 2012 tira a tag <script> e </script> do ficheiro .js Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast." Link to comment Share on other sites More sharing options...
jsalitre Posted June 19, 2012 Report Share Posted June 19, 2012 O que normalmente faço é usar a framework Jquery, mesmo que no teu caso não uses nada de JQuery, podes sempre fazer: <script type="text/javascript" src="<caminhoparaoficheiro>/jquery.js"></script> (A ordem é extremamente importante) <script type="text/javascript"> $(document).ready(function() { alert("hello"); //Tudo o que estiver aqui dentro será executado quando o evento load do "document" disparar. }); </script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now