简单的装载、计数和处理形式
我需要一些有关我正在开发的脚本的帮助。我有一些广告。
当用户点击广告时,将打开一个新页面。
在该新页面上,将有一个用于状态消息的 div,在该 div 下方有一个大 iframe。
我想要这样的:
1. 在状态消息框中,应显示“正在加载 iFrame 的内容...”(直到 iFrame 的 url 已完全加载)
2. 它应该从 X 秒/加载栏开始倒计时。
3. 当它达到零时,应该运行一个表单,并在状态 div 中输出数据。
有人可以帮我获得这个吗?这一切都应该使用 jQuery 完成,无需任何重新加载。
到目前为止我已经知道了:
var countDownTimer = null;
var seconds = <?php echo $exposure[$r['exposure']]; ?>;
function setCountDownTimer(){
if(countDownTimer)
clearTimeout(countDownTimer);
countDownTimer = setTimeout(updateCountdown, 1000);
};
function updateCountdown() {
countDownTimer = null;
seconds--;
if (seconds > 0) {
$("#countdown").text("You must view this advertisement for " + seconds + " seconds.");
//$('#progressbar').progressbar({ value: Math.round((seconds/10)*100) });
setCountDownTimer();
} else {
submitForm();
}
}
// on document load:
$(function() {
$("#progressbar").progressbar({ value: 0 });
// set "waiting" message:
$("#loadingStatus").html("Waiting for your advertisements to load...");
// on iframe load:
$('#iFrame').load(function() {
$("#loadingStatus").html($("#isDone").html());
//Attached click event to the link inside iframe to restart the timer
var iframe = $('#iFrame');
iframe.contents().find("linkSelector").click(function(){
window.top.setCountDownTimer();
});
});
setCountDownTimer();
});
function submitForm() {
$("#countdown").empty().html('<img src="..ify/dream/images/loading.gif" />');
$.post(
'index.php?i=v&p=k&key=DSF79SADFHSA7D9FGSAD097FSAD7F9779ASDFGS9',
$('form').serialize(),
function (data) {
proccessData(data);
}
);
}
function proccessData (data) {
$('#statusF').hide().html('');
if(data=='success'){
$('form').fadeOut();
$('#countdown').addClass('noti-success').html('Advertisement validated!').slideDown();
redirect("?i=l");
}
else {
$('#countdown').addClass('noti-error').html(data).fadeIn();
}
}
上面代码的问题是,当用户单击 iframe 时,状态消息计时器会混乱。所以 :/
I need some help with a script I am developing. I have some advertisements.
When a user clicks on the advertisement, a new page will open up.
On that new page, there will be an div for status messages, and below that div a big iframe.
I want it like this:
1. In the status message box, it should say "Loading content of iFrame..." (Until the url of the iFrame has been fully loaded)
2. It should countdown from X seconds / loading bar.
3. When it hits zero, a form should run, and output data in the status div.
Can someone please help me obtain this? It should all be done with jQuery and without any reloads.
I HAVE THIS SO FAR:
var countDownTimer = null;
var seconds = <?php echo $exposure[$r['exposure']]; ?>;
function setCountDownTimer(){
if(countDownTimer)
clearTimeout(countDownTimer);
countDownTimer = setTimeout(updateCountdown, 1000);
};
function updateCountdown() {
countDownTimer = null;
seconds--;
if (seconds > 0) {
$("#countdown").text("You must view this advertisement for " + seconds + " seconds.");
//$('#progressbar').progressbar({ value: Math.round((seconds/10)*100) });
setCountDownTimer();
} else {
submitForm();
}
}
// on document load:
$(function() {
$("#progressbar").progressbar({ value: 0 });
// set "waiting" message:
$("#loadingStatus").html("Waiting for your advertisements to load...");
// on iframe load:
$('#iFrame').load(function() {
$("#loadingStatus").html($("#isDone").html());
//Attached click event to the link inside iframe to restart the timer
var iframe = $('#iFrame');
iframe.contents().find("linkSelector").click(function(){
window.top.setCountDownTimer();
});
});
setCountDownTimer();
});
function submitForm() {
$("#countdown").empty().html('<img src="..ify/dream/images/loading.gif" />');
$.post(
'index.php?i=v&p=k&key=DSF79SADFHSA7D9FGSAD097FSAD7F9779ASDFGS9',
$('form').serialize(),
function (data) {
proccessData(data);
}
);
}
function proccessData (data) {
$('#statusF').hide().html('');
if(data=='success'){
$('form').fadeOut();
$('#countdown').addClass('noti-success').html('Advertisement validated!').slideDown();
redirect("?i=l");
}
else {
$('#countdown').addClass('noti-error').html(data).fadeIn();
}
}
The problem with the code above, is that when a user for example clicks in the iframe, the status message timer will mess up. So :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 jQuery.ajax 方法(或其派生方法之一)。使用 jQuery.ajax,您可以将所需的任何数据发送到服务器以“运行表单”(如您所提到的),当您返回 html 时,您可以将其保存在变量中。然后,您可以使用计时器对象在超时到期时将 div 的 html 设置为新内容。
You need to use the jQuery.ajax method (or one of its derivatives). Using jQuery.ajax, you can send whatever data you need to the server to "run a form" (as you mentioned) and when you get html back, you can save it in a variable. You can then use your timer object to set the html of the div to the new content when the timeout expires.