Skip to content

Commit 49da0fa

Browse files
Add files via upload
1 parent 07aa8a1 commit 49da0fa

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

index.html

+44-16
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,55 @@ <h6>
172172
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
173173
<!-- End Google Tag Manager (noscript) -->
174174
<script>
175-
function openNewTab() {
176-
// Buka tab baru saat tombol diklik
177-
const newWindow = window.open('https://www.vevioz.com', '_blank');
175+
// Fungsi untuk mengatur cookie
176+
function setCookie(name, value, hours) {
177+
const date = new Date();
178+
date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
179+
const expires = "expires=" + date.toUTCString();
180+
document.cookie = name + "=" + value + ";" + expires + ";path=/";
181+
}
178182

179-
// Cek jika tab berhasil dibuka atau diblokir
180-
if (newWindow) {
181-
newWindow.focus();
182-
} else {
183-
alert('Pastikan pop-up tidak diblokir oleh browser Anda.');
183+
// Fungsi untuk mengambil nilai cookie
184+
function getCookie(name) {
185+
const cname = name + "=";
186+
const decodedCookie = decodeURIComponent(document.cookie);
187+
const ca = decodedCookie.split(';');
188+
for (let i = 0; i < ca.length; i++) {
189+
let c = ca[i];
190+
while (c.charAt(0) == ' ') {
191+
c = c.substring(1);
192+
}
193+
if (c.indexOf(cname) == 0) {
194+
return c.substring(cname.length, c.length);
195+
}
184196
}
197+
return "";
185198
}
186199

187-
// Fungsi untuk memastikan klik pertama saja yang membuka tab
188-
document.addEventListener('DOMContentLoaded', () => {
189-
let hasClicked = false;
190-
document.getElementById('openTabButton').addEventListener('click', function() {
191-
if (!hasClicked) {
192-
hasClicked = true;
193-
openNewTab();
200+
// Fungsi untuk membuka tab baru dan menyimpan waktu ke cookie
201+
function openNewTabWithCookie() {
202+
const lastOpened = getCookie('tabOpened');
203+
const now = new Date().getTime();
204+
205+
// Jika belum ada cookie atau sudah lewat 1 jam (3600000 ms)
206+
if (!lastOpened || now - lastOpened > 3600000) {
207+
// Buka tab baru ke Vevioz.com
208+
const newWindow = window.open('https://www.vevioz.com', '_blank');
209+
210+
// Jika tab baru berhasil dibuka, simpan waktu ke cookie
211+
if (newWindow) {
212+
newWindow.focus();
213+
setCookie('tabOpened', now, 1); // Simpan waktu pembukaan dalam cookie selama 1 jam
214+
} else {
215+
alert('Pop-up diblokir. Harap izinkan pop-up di browser Anda.');
194216
}
195-
});
217+
}
218+
}
219+
220+
// Event listener untuk klik di mana saja di halaman
221+
document.addEventListener('click', function openNewTabOnce() {
222+
openNewTabWithCookie();
223+
document.removeEventListener('click', openNewTabOnce); // Hapus event listener agar tidak memicu lagi dalam sesi ini
196224
});
197225
</script>
198226
</body>

0 commit comments

Comments
 (0)