Mengalihkan halaman web atau bahasa inggris nya redirect page bisa dilakukan menggunakan javascript (clientside), yaitu dengan perintah berikut :
1
2
3
|
< script type = "text/javascript" > window.location = "http://www.google.com"; < script > |
Perintah diatas akan mengalihkan halaman (redirect) menuju ke situs google.com
Sekarang kita coba buat function dalam javascript untuk redirect page.
1
2
3
4
5
6
|
< script type = "text/javascript" > function pindah(url) { window.location = url; } </ script > |
Berikut ini contoh penggunaanya, buka notepad copy-paste kode berikut, lalu simpan sebagai coba.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
< html > < head > < title >Contoh Program</ title > < script type = "text/javascript" > function pindah(url) { window.location = url; } </ script > </ head > < body > < input type = "button" onclick = "pindah('contact.html')" value = "klik dong" <br/>< br /> < input type = "button" onclick = "pindah('http://www.google.com')" value = "klik lagi" <br/> </ body > </ html > |
Kita juga bisa menambahkan timer menggunakan fungsi setInterval() seperti berikut ini :
1
2
3
4
5
6
7
|
< script type = "text/javascript" > function pindah(url) { window.location = url; } setInterval("pindah('tes.html')",2000); </ script > |
Selamat mencoba
Terima kasih infonya, web yang aku kelola jadi lebih user friendly
Thanks , I’ve recently been looking for information about this topic for
a long time and yours is the best I’ve found out so far.
But, what about the bottom line? Are you positive concerning the source?
Kalo misalnya biar targetnya blank bisa g?
tinggal dibikin html yg isinya blank aja