كود بلغة HTML:
<!doctype html>
<html lang="en">
<head>
<title>test - timer</title>
</head>
<body>
<span id="countdown" class="timer" style="font-size: 18px; font-weight: Bold"></span>
<script>
var seconds =10;
function secondpassed() {
var minutes = math.round((seconds - 30)/60);
var remainingseconds = seconds % 60;
if (remainingseconds < 10) {
remainingseconds = "0" + remainingseconds;
}
document.getelementbyid('countdown').innerhtml = minutes + ":" + remainingseconds;
// focus part
if (seconds == 0) {
clearinterval(countdowntimer);
document.getelementbyid('countdown').innerhtml = "<a href='download.php?file=book.pdf'>download file</a>";
} else {
seconds--;
}
} var countdowntimer = setinterval('secondpassed()', 1000);
********onblur = function (){
clearinterval(countdowntimer);
document.getelementbyid('countdown').innerhtml = "<h5>please refr esh to generate download url.<h5>";
}
// too make it complete, also add onblur to document.
// for browsers using tabs (like firefox)
document.onblur = win dow.onblur;
document.focus = win dow.focus;
</script>
</body>
</html>
تفضل اخي
غير قيمة متغير var بعدد الثواني التي ترغب بانقضائها
هنا انا وضعت قيمتها 10 ثواني
اذا ادرت مثلا دقيقتين ضع 120
ويمكنك التحكم فيما سوف يظهر بعد انقضاء المدة بوضع مثلا رابط التحميل في هذا السطر
كود بلغة HTML:
document.getelementbyid('countdown').innerhtml = "<a href='download.php?file=book.pdf'>download file</a>";
حيث انا وضعت على سبيل المثال رابط تحميل كتاب باسم book.pdf
والكود مبرمج بخاصية عدم فقدان التركيز على الصفحة او النافذة
فاذا مثلا الزائر كان في صفحة التحميل و انتقل الى صفحة أخرى او نافذة اخرى بدون انقضاء المدة سوف تظهر له الرسالة
كود بلغة HTML:
please ref resh to generate download url.
اخي احذف الفراغ بين ref resh او غيرها على حسب حاجتك
واحذف الفراغ بين
كود بلغة HTML:
document.onblur = win dow.onblur;
document.focus = win dow.focus;
لأن منتدى الجلفة يظهرها على شكل نجوم
بالتوفيق