How to detect adblock without changing or refreshing URL - ajax

I am using "adframe" library to detect adblock and it works just fine.
However, I am having an issue in a webpage that loads content through AJAX.
If the visitor enters to this page with adblock enabled, then the library detects it and the content is not displayed, but if the user enters to this page with adblock disabled, then the content is shown and ALL FUTURE content loaded through AJAX will be shown regardless the user enables adblock or not while he is on this page and that is my problem.
I am trying to detect adblock in the same URL, while AJAX functions are being executed.
Bellow is one of the functions... is it posible to detect adblock in between??
function action1(time,id_object)
{
if(time != -1){
$("#time_object").html(time);
time2 = time - 1;
id_object2 = id_object;
count = setTimeout('action1(time2,id_object2);', 1000);
}
else
{
if(id_object != 0)
{
clearTimeout(count);
$('#feedback').modal('show');
$.ajax({
async:true,
dataType: "html",
type: "POST",
data: {id_object: id_object},
contentType: "application/x-www-form-urlencoded",
url: "site/show_object.php",
beforeSend:function(){
$('#feedback').html(loading);
},
success:function(data){
$('#feedback').html(data);
count = setTimeout('webpage3()',60000);
},
timeout:20000,
error:function(){
location.href= 'webpage4';
}
});
return 0;
}
else
{
next();
}
}
}

Add following snippet and check console for message
HTML
<div id="addBlockerDiv">
<div class="adBanner" style="background-color: transparent;height:1px;width:1px;">
</div>
</div>
JS
window.onload = function(){
if(document.getElementById("addBlockerDiv").clientHeight > 0) {
console.log('adblock not present');
} else {
console.log('adblock present');
}
}

Related

refresh the page with ajax on a social network website

I want to create a social network website. but there is a problem when the page refreshes the page with ajax. there I am using setInterval every 5 seconds. but by the time the page refreshes, textarea also comments on reloading. how to order textarea in the comments do not reload when the page refreshes?
please help me !
Can You put up your Code in order to understand your problem more Precisely.?
Use :
$.ajax({
url: '--URL of ajax Page--',
type: 'POST',
data: {},
success: function(data) {
$(document).ajaxStop(function() {
**window.location.reload();** // This reloads the Page in a faster way.
});
}
});
my code like this:
The page refreshes (_view.php)
<div class="status">
<?php echo ' <span style="color: #f83e07">#SIF# '.$data->idUser->short_name.'</span> : '.date("D, d M Y, H:m:s",strtotime($data->tgl_update)).'</br>'.CHtml::link(CHtml::image(Yii::app()->baseUrl.'/images/member/'.$data->idUser->foto,'',array("width"=>50,"height"=>50)), array('user/view', 'id'=>$data->id_user)).'</br>';
if($data->id_user == Yii::app()->user->id){
}
echo '</br><div class="isi">'.strip_tags($data->isi, "<h1><u><div><br><h2><h3><h4><h5><h6><img><hr><font><b>").'</div>'; ?>``
reload the index page (index.php)
function callAjax(){
$.fn.yiiListView.update('datalist', {
data: $(this).serialize(),
success: function(html){
$('.view').mouseout(function(e){
ref = setInterval(function(){callAjax();}, 5000);
});
$('.view').click(function(e){
clearInterval(ref);
});
},
}
);
}

Ajax loaded content div class is not applied

I have a page that has a few divs connected in a flowchart via JS-Graph.It. When you click one of the divs, I want it to 1) generate text in a special div 2) generate a popup via click functions attached to the two classes "block" and "channel" in each div. This works when the page is static.
When I add ajax so on click of a button and add more divs, only one of the two classes appears in the HTML source. "Channel" is no longer visible and the function to generate a pop-up on click of a channel class div does not work anymore...
AJAX call:
$("#trace").bind('click', $.proxy(function(event) {
var button2 = $('#combo').val();
if(button2 == 'default') {
var trans = 'Default View';
}
if(button2 == 'abc') {
var trans = 'abc';
}
$.ajax({ // ajax call starts
url: 'serverside.php', // JQuery loads serverside.php
data: 'button2=' + $('#combo').val(), // Send value of the clicked button
dataType: 'json', // Choosing a JSON datatype
success: function(data) // Variable data constains the data we get from serverside
{
JSGraphIt.delCanvas('mainCanvas');
$('.test').html('<h1>' + trans + '</h1>'); // Clear #content div
$('#mainCanvas').html(''); // Clear #content div
$('#mainCanvas').append(data);
JSGraphIt.initPageObjects();
}
});
return false; // keeps the page from not refreshing
}, this));
DIV class: (works in index.php but not transactions.php)
// Boxes
while($row = sqlsrv_fetch_array($result))
{
echo '<div id="'.$row['id'].'_block" class="block channel" style="background:';
Functions:
$(document).on('click', '.block', $.proxy(function(event) {
var input = $(event.target).attr('id');
var lines = input.split('_');
var button = lines[0];
$.ajax({
url: 'srv.php',
data: 'button=' + button,
dataType: 'json',
success: function(data)
{
$('#content').html('');
$('#content').append(data);
}
});
return false;
}, this)); // End Application Details
$(".channel").click(function () {
alert('channel');
});
Something about registering with pages, I'm not sure exactly how it works. The fix should be to change your channel click function to be the same as your first and use the .on('click') option.
found some related reading material. https://learn.jquery.com/events/event-delegation/

Joomla mootools Ajax request always returning response text suffixed by '[]'

I am having a peculiar problem. I am trying to validate some card numbers using AJAX. Entire process goes fine and I am getting response from the script as expected. But I am not sure why all the response texts (even if it is an empty string) will show a [] suffixed to it when I alert it on my javascript. If I give an alert directly from the javascript, it shows fine. But all the responses from AJAX gives the above mentioned output.
Can anyone give me a clue why this is happening? I might have done something stupid in my code... but not able to figure out what... Any inputs will be highly appreciated.
Thanks in advance
EDIT:
Javascript Code:
var url = '" . JURI::base() . "index.php?option=<component>&view=<view>&format=raw&task=<task>';
var a = new Request({
url: url,
data: {
'".JUtility::getToken()."': 1
},
method: 'post',
onSuccess: function(responseText) {
alert(responseText);
},
onFailure: function(xhr) {
alert('Failed');
}
}).send();
PHP Script on view.raw.php
<?php echo "Here"; ?>
This script when run, will throw the alert message as "Here[]"
---- RENDERED JAVASCRIPT CODE ---
window.addEvent('domready',function() {
if($('addpluspayment')) {
$('addpluspayment').addEvent('click', function(event) {
bbCardNum = $('bbpluscardpayment').value;
if(bbCardNum.length <= 0) {
alert('Número de tarjeta no válida');
return;
}
totalAmountToCheck = parseFloat($('taqPaymentAmount').value);
var url = 'http://mydomain.com/index.php?option=com_bbpayment&view=taqcart&format=raw&task=bbcheckpoints';
var a = new Request({
url: url,
data: {'5df1de004436f241ef112345035bab51':1,'totalAmountToCheck':totalAmountToCheck,'bbCardNum':bbCardNum},
method: 'post',
onSuccess: function(responseText) {
if(responseText == 'othercategories[]') {
alert('Entradas encontradas en otras categorías');
}
else {
alert(responseText);
}
},
onFailure: function(xhr) {
alert('Failed');
}
}).send();
});
}
});
Here, the alerts - 'Número de tarjeta no válida', 'Entradas encontradas en otras categorías' and 'Failed' (which are directly thrown from the javascript) comes up without any problems.. but all responseText alerts suffix a [], even if the PHP script echos just 'Hello' (which will throw the alert as 'Hello[]')

AJAX first attempt json data element not changing

Hi I have my first AJAX JSON working and it returns C5:3; at the moment for development and displays this in a div, a img tag should be replaced from a off.png to a on.png but this isn't happening. Would appreciate if anyone could through some light on this?? here is my code
$("button.checkStatus").click(function(){
//This Ajax checks the current on/off status of the passed X10 code
$('img.checkStatus').each(function(i, obj) {
$x10Device = $(this).data("x10");
var postData = "url=http://local/tenHsServer/tenHsServer.aspx?t=ab&
f=DeviceStatus&d=" + $x10Device ;
$.ajax({
type: "POST",
dataType: "json",
data: postData,
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8");
}
},
url: 'urlencodeJson.php',
success: function(data) {
// 'data' is a JSON object which we can access directly.
// Evaluate the data.success member and do something appropriate...
if (data.success == true){
$('#section1').html(data.message);
$("X10").data('src','lightbulbon.png');
}
else{
$('#section2').html(data.message);
$("X10").data('src','lightbulbon.png');
}
}
});
The HTML
<img src="lightbulboff.png" class="checkStatus" data-x10="C5">
<img src="lightbulboff.png" class="checkStatus" data-x10="C6">
<img src="lightbulboff.png" class="checkStatus" data-x10="C7">
<button class="checkStatus">Device Status Check</button>
<div id="section1"></div>
<div id="section2"></div>
This is driving me crazy!!! every way tried over the last 2 days hit a brick wall would be great if I could crack it!!!
Many thanks!!!
I think you could change a couple of things to make it works, first of all change the success part inside your ajax request:
$("X10").data('src','lightbulbon.png');
this wont lead you anywhere, since you're addressing nothing, insted save you current object in a variable and change it (or use the $(this) context where this is your current image object) :
$(this).attr('src','lightbulbon.png');
another little thing is how you set up the call, while it's not wrong, doing :
$x10Device = $(this).data("x10");
var postData = "url=http://local/tenHsServer/tenHsServer.aspx?t=ab&
f=DeviceStatus&d=" + $x10Device ;
could be a little redundant and can lead to easy error while you setup a post request, just rewrite it like an array :
data: {url : 'http://local/tenHsServer/tenHsServer.aspx?t=ab',
f : 'DeviceStatus',
d: $(this).data("x10") }
the whole function should be like :
$("button.checkStatus").click(function(){
$('img.checkStatus').each(function(i, obj) {
var element = $(this);
$.ajax({
type: "POST",
url: 'urlencodeJson.php',
dataType: "json",
data: { url : 'http://local/tenHsServer/tenHsServer.aspx?t=ab',
f : 'DeviceStatus',
d: $(this).data("x10") },
beforeSend: function(x) {
if(x && x.overrideMimeType) {
x.overrideMimeType("application/json;charset=UTF-8");
},
success: function(data) {
if (data.success == true){
$('#section1').html(data.message);
element.attr('src','lightbulbon.png');
}
else{
$('#section2').html(data.message);
element.attr('src','lightbulbon.png');
}
}
});
});
});

jquery tabs not firing after content loaded via ajax

I have an index page, in wich I have jquery.js and jquery.tabs.js included.
this page load content via ajax into a . The content is a set of tabs, their contents and at the bottom of the loaded content I have a call to tabs().
in FF it only works when I load content after refreshing the index page, and if I hit the link to reload the content, it stops working. in IE it's not working at all.
These are my tabs:
<ul id="horz-tabs">
<li>tab1</li>
<li>tab2</li>
<li>tab3</li>
</ul>
then I have the containers following, and at the very end of the page loaded via ajax I have:
<script type="text/javascript"><!--
$('#horz-tabs a').tabs();
//--></script>
My ajax function loads the page properly. I am wondering how I can fix this issue. Thanks for any help or advice.
The ajax loading function is as follow
<script>
function async(target, href) {
var loading = '<div class="loading">Loading</div>';
jQuery.ajax({
url: href,
beforeSend: function() {
$(target).prepend(loading);
},
error: function() {
$(target).html("<span class='error'>Failed</span>");
},
success: function(results) {
$(target).html(results);
}
})
}
</script
Look like you are loading the tab html via ajax, that could be the problem since when your script is running the dom for the tab elements may not be existing.
So you need to have a success callback to the async load method and add execute $('#horz-tabs a').tabs(); in the load success callback.
function async(target, href) {
var loading = '<div class="loading">Loading</div>';
return jQuery.ajax({
url : href,
beforeSend : function() {
$(target).prepend(loading);
},
error : function() {
$(target).html("<span class='error'>Failed</span>");
},
success : function(results) {
$(target).html(results);
}
});
}
Then
async('some-div', 'tab-url').done(function(){
$('#horz-tabs a').tabs();
})

Resources