【发布时间】:2021-07-11 12:09:14
【问题描述】:
我正在开发代理服务,一切正常。当您按下提交按钮时,它具有 onclick 功能。我现在也让它检测何时启用 adblock,如果检测到 adblock,我不希望该功能通过,(这意味着我想要它,所以如果你启用了 adblock,代理实际上不会启动,我想要只有当您按下按钮直到您禁用广告拦截时才会弹出警报消息。)
如果您有广告拦截,这是我正在寻找的示例。 (http://fastp.org/) 在这个网站上,如果你启用了adblock,你就不能提交表单。在警报框上按“确定”后,我的仍然通过。在我的 javascript 代码中,我尝试执行“return false”;还有一个“其他”,但似乎没有任何效果。如果您启用了广告屏蔽,我不希望提交表单。
我想要它,所以如果启用了 adblock,它将显示警告框,并且当您按“确定”时,我不希望它仍然在新标签中启动代理。我希望它在 adblock 被禁用时启动。
这是我的代码:
$(document).ready(function() {
$('#browsebtn').click(function() {
val = $('#urlinput').val();
$('#urlinput').val(val.replace($('#remove1').val(), ""));
});
});
$(document).ready(function() {
$('#browsebtn').click(function() {
val = $('#urlinput').val();
$('#urlinput').val(val.replace($('#remove2').val(), ""));
});
});
$(document).ready(function() {
$('#browsebtn').click(function() {
val = $('#urlinput').val();
$('#urlinput').val(val.replace($('#remove3').val(), ""));
});
});
function forceLower(strInput) {
strInput.value = strInput.value.toLowerCase();
}
function checkAdBlocker() {
try {
fetch(
new Request("https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js", {
method: 'HEAD',
mode: 'no-cors'
})).catch(error => {
showNotification();
});
} catch (e) {
// Request failed, likely due to ad blocker
showNotification();
}
var x;
x = document.getElementById("urlinput").value;
if (x == "" || x == "https://" || x == "http://" || x == "www." || x == "http://www." || x == "https://www.") {
$("#error").show().delay(3000).fadeOut();
return false;
} else {
var ddl = document.getElementById("servertype");
var selectedValue = ddl.options[ddl.selectedIndex].value;
if (selectedValue == "server1") {
setTimeout(function() {
window.open('http://server1.com/' + document.getElementById('urlinput').value);
}, 200);
}
if (selectedValue == "server2") {
setTimeout(function() {
window.open('http://server2.com/' + document.getElementById('urlinput').value);
}, 200);
}
if (selectedValue == "server3") {
setTimeout(function() {
window.open('http://server3.com/' + document.getElementById('urlinput').value);
}, 200);
}
if (selectedValue == "server4") {
setTimeout(function() {
window.open('http://server4.com/' + document.getElementById('urlinput').value);
}, 200);
}
}
}
function showNotification() {
alert("Please disable adBlocker");
}
<form action="javascript:void(0);" method="POST">
<input id="remove1" type="hidden" value="https://" /><input id="remove2" type="hidden" value="http://" /><input id="remove3" type="hidden" value="www." />
<input type="text" name="name" placeholder="Enter web address.." id="urlinput" onkeyup="return forceLower(this);" /><button type="submit" id="browsebtn" onclick="return checkAdBlocker()" name="submit" value="Browse">BROWSE</button>
<div class="serverselect"><label>Select Server:</label></div>
<div class="selectserver">
<select id="servertype" name="dropdown">
<option value="server1" data-sort="1">???????? US Server</option>
<option value="server2" data-sort="2">???????? CA Server</option>
<option value="server3" data-sort="3">???????? DE Server</option>
<option value="server4" data-sort="4">???????? GB Server</option>
</select>
</div>
<p id="error">Please enter a valid URL address.</p>
</form>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
抱歉,是的,我知道代码很长,但我想确保新代码不会影响任何遗漏的代码。 (一切都在循环中)感谢您的观看。
【问题讨论】:
标签: javascript html jquery