reset and begin
Showing posts with label Javascript. Show all posts

10/31/2010

lấy thông tin thời tiết bằng Javascript

Thông tin về thời tiết là một trong những widget hay được hiển thị nhất trên các website tin tức. Tuy vậy, có nhiều web master không biết cách làm widget này. Tôi thường thấy người ta "mượn tạm" các file javascript hoặc lọc nội dung trên các website nổi tiếng như VnExpress, Dân trí, ... rồi hiện chúng trên website của mình. Cách làm như vậy khiến website của mình phụ thuộc vào các trang đó, đồng thời cũng khó tùy biến.

Bài viết này sẽ chia sẻ cho các bạn cách lấy thông tin dự báo thời tiết và hiển thị chúng trên website 1 cách đơn giản. Thông tin thời tiết này được lấy từ Yahoo! nên có thể đảm bảo độ chính xác và tin cậy.

Cách hiển thị thông tin thời tiết trên website


Để hiển thị thông tin thời tiết trên website, bạn chỉ cần chèn đoạn code sau vào trong thẻ head:

<script type="text/javascript" src="http://rilwis.googlecode.com/svn/trunk/weather.min.js"></script>

Sau đó, ở vị trí bạn muốn hiển thị thông tin thời tiết, bạn chỉ cần chèn đoạn code:

<script type="text/javascript">
showWeather('hanoi, vietnam');
</script>

10/13/2010

tạo đếm ngược thời gian với javascript count down javascript

tạo đếm ngược thời gian với javascript count down javascript
<form name="counter"><input type="text" size="8"
name="d2"></form>

<script>
<!--
//
var milisec=0
var seconds=30
document.counter.d2.value='30'

function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.counter.d2.value=seconds+"."+milisec
setTimeout("display()",100)
}
display()
-->
</script>

7/02/2010

tạo nút thẻ a

<html>
<body>
<script>
var links=document.createElement('a');
links.setAttribute("href","http://www.yahoo.com");
links.textContent="yahoo";
document.body.appendChild(links);

var newdiv = document.createElement('div');
newdiv.setAttribute("id","moot450");
newdiv.setAttribute("style", "position:absolute; border:2px solid #000000; width:300px; height:300px;");
document.body.appendChild(newdiv);


</script>
</body>
</html>

4/29/2010

chuyen anh theo thoi gian

<code>
// Created by: Lee Underwood :: http://javascript.internet.com/
var t;
var bannerImg = new Array();
// Enter the names of the images below
bannerImg[0]="1.jpg";
bannerImg[1]="2.jpg";
bannerImg[2]="3.jpg";

var linkimg = new Array();

linkimg[0]="http://dantri.com.vn";
linkimg[1]="http://vtc.vn";
linkimg[2]="http://saovn.com";
var newBanner = 0
var totalBan = bannerImg.length

function cycleBan() {
newBanner++
if (newBanner == totalBan) {
newBanner = 0
}
document.banner.src=bannerImg[newBanner]
document.getElementById('linkchuyen').href=linkimg[newBanner]
t=setTimeout("cycleBan()", 2*1000)
}
function stop(){
clearTimeout(t);
}

window.onload=cycleBan;


a img{
border:3px solid #f2f2f2;
margin:2px;
}

<a href="#" name="linkchuyen" id="linkchuyen">
<img src="1.jpg" width="300px" height="200px">
</a>
</code>

chuyen link va anh javascript


// Created by: Lee Underwood :: http://javascript.internet.com/
var t;
var bannerImg = new Array();
// Enter the names of the images below
bannerImg[0]="1.jpg";
bannerImg[1]="2.jpg";
bannerImg[2]="3.jpg";

var linkimg = new Array();

linkimg[0]="http://dantri.com.vn";
linkimg[1]="http://vtc.vn";
linkimg[2]="http://saovn.com";
var newBanner = 0
var totalBan = bannerImg.length

function cycleBan() {
newBanner++
if (newBanner == totalBan) {
newBanner = 0
}
document.banner.src=bannerImg[newBanner]
document.getElementById('linkchuyen').href=linkimg[newBanner]
t=setTimeout("cycleBan()", 2*1000)
}
function stop(){
clearTimeout(t);
}

window.onload=cycleBan;


a img{
border:3px solid #f2f2f2;
margin:2px;
}





4/24/2010

xoay hình trong css javascript

css
/* for firefox, safari, chrome, etc. */
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
/* for ie */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
script

Image Rotate








var ImageArr1 = new Array("Picture(3).jpg","Picture(1).jpg","Picture(2).jpg");
var ImageHolder1 = document.getElementById('Rotating1');

var ImageArr2 = new Array("Picture(5).jpg","Picture(6).jpg","Picture(7).jpg");
var ImageHolder2 = document.getElementById('Rotating2');

function RotateImages(whichHolder,Start)
{
var a = eval("ImageArr"+whichHolder);
var b = eval("ImageHolder"+whichHolder);
if(Start>=a.length)
Start=0;
b.src = a[Start];
window.setTimeout("RotateImages("+whichHolder+","+(Start+1)+")",1500);
}

RotateImages(1,0);
RotateImages(2,0);





3/31/2010

javascript lấy link hiện tại

<script language="javascript" type="text/javascript">
document.write (document.location.href);
</script>

to get the full url from my browser using javascript

List

Profiles Information


About me : Nothing is 1 vài thứ - 1985

Places I've Lived : I Hà Nội

Home Page : http://www.shimivn.blogspot.com/

Think : 1:1000000000

Languages spoken : Vietnamese,English.

Mobile : sony C2305

dell : i3-Ram 3GB- HDD 250GB .