Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by Wilson Edwards
at 2025-01-23 19:49:42
Point:500 Replies:5 POST_ID:829292USER_ID:12108
Topic:
javascript;jquery;php
$(document).click(function(e) {
// ####Check for left button
if (e.button == 0) {
// alert('clicked');
console.log('page......clicking');
checkhitrate('ads_hitrate');//check the document.activeElememnt source such as ifram or <a> tag
}else {}
});
it works but can not detect mouse right click or mouse left click;
so try to other code such as follows
var mouseleft=null;
document.addEventListener('mousedown', function(event) {
switch (event.button) {
case 0:
mouseleft=1;
checkhitrate('ads_hitrate');
console.log('mouse Left button clicked.');
break;
case 1:
mouseleft=0;
console.log('mouse Middle button clicked.');
break;
case 2:
mouseleft=0;
console.log('mouse Right button clicked.');
break;
case 3:
mouseleft=0;
console.log('mouse Browser Back button clicked.');
break;
case 4:
console.log('Browser Forward button clicked.');
break;
default:
console.log('Unknown button clicked.');
}
});
*/
it is working ok, but not work if the content area with iframe...
so we need use blur as follows
window.addEventListener('blur', notFocused);
function notFocused() {
localStorage.setItem('focus','0');
setTimeout(()=>{$(window).focus();},200);
checkhitrate('ads_hitrate');
console.log('NOT focused',ia2++);
return 0;
}
and check whether visitor leave current page to forward to other site
, use this function becoz we can not idenity it is right or left click.
if.onbeforeunload even is triggered it mean it is from left click
window.onbeforeunload=function(e){
console.log('hist-onbeforeunload');
localStorage.removeItem("stateHistoryonbeforeunload");
localStorage.setItem("stateHistoryonbeforeunload", 1);
}
eventonbeforeunload should be earlier than checkrate();
function checkhitrate(hitrate){
if (hitrate=='ads_hitrate')sendclick();
}
function sendclick(){
if (document.activeElement.src) var tmp=document.activeElement.src ; else tmp=""
if (document.activeElement.tagName === "IFRAME"){
if (tmp.indexOf('client=ca-pub-')>0){
setTimeout(()=>{
console.log('notfocused _post3',"stateHistoryonbeforeunload",localStorage.getItem("stateHistoryonbeforeunload"));
document.activeElement.blur();
if (localStorage.getItem("stateHistoryonbeforeunload")=="1"){
_post3(url,JSON.stringify(obj),fun);
localStorage.removeItem("stateHistoryonbeforeunload")
}
},200);
}
}
Note: every click then clear lastdocument.activeElement bydocument.activeElement.blur() sonext check click will be working again
Author: Wilson Edwards replied at 2025-01-20 16:30:00
u can also check with document.referrer for previous history siteaddress..but not always works
Author: Wilson Edwards replied at 2025-01-20 16:28:07
https://stackoverflow.com/questions/3995524/is-it-possible-to-change-document-activeelement-in-javascript
Author: Wilson Edwards replied at 2025-01-20 16:27:37
https://stackoverflow.com/questions/10035564/is-there-a-cross-browser-solution-for-monitoring-when-the-document-activeelement
Author: Wilson Edwards replied at 2025-01-20 16:22:13
You can also try following function for previous forward URL site list
but it is not working, just for a good starting
window.addEventListener('popstate', function(event) {
console.log('Previous URL:', event.state?.previousURL || 'No previous URL saved');
});
var hist = [];
$(window).bind('hashchange', function() {
console.log('hist-hashchange');
hist.push(location.hash);
});
$(window).bind("statechange", function() {
console.log('hist-statechange');
var historyStack = localStorage.getItem("stateHistory") === null ? [] : JSON.parse(localStorage.getItem("stateHistory"));
historyStack.push(window.location.search.substr(1));
localStorage.setItem("stateHistory", JSON.stringify(historyStack));
});
history.length
history, forwards();
hsitory.back();
history.go(integer);
Author: Wilson Edwards replied at 2025-01-20 16:18:21
u can use jquery to detect iframe or other <a> tag; following is reference only, it just now working for iframe only, u can modify it for <a> tag
(function($) {
setTimeout(()=>{
console.log('Tagname');
// Tracking handler manager
$.fn.iframeTracker = function(handler) {
// Building handler object from handler function
if (typeof handler == "function") {
handler = {blurCallback: handler};}
var target = this.get();
if (handler === null || handler === false) {
$.iframeTracker.untrack(target);
} else if (typeof handler == "object") {
$.iframeTracker.track(target, handler);
} else {
throw new Error("Wrong handler type (must be an object, or null|false to untrack)");
}
return this;};
// Iframe tracker common object
$.iframeTracker = {
// State
focusRetriever: null, // Element used for restoring focus on window (element)
focusRetrieved: false, // Says if the focus was retrieved on the current page (bool)
handlersList: [], // Store a list of every trakers (created by calling $(selector).iframeTracker...)
isIE8AndOlder: false, // true for Internet Explorer 8 and older
// Init (called once on document ready)
init: function() {
// Determine browser version (IE8-) ($.browser.msie is deprecated since jQuery 1.9)
try {
if ($.browser.msie === true && $.browser.version < 9) {
this.isIE8AndOlder = true;
}
} catch (ex) {
try {var matches = navigator.userAgent.match(/(msie) ([\w.]+)/i);
if (matches[2] < 9) {this.isIE8AndOlder = true;}
} catch (ex2) {}
}
// Listening window blur
$(window).focus();
$(window).blur(function(e) {
$.iframeTracker.windowLoseFocus(e);
});
// Focus retriever (get the focus back to the page, on mouse move)
$("body").append('<div style="position:fixed; top:0; left:0; overflow:hidden;"><input style="position:absolute; left:-300px;" type="text" value="" id="focus_retriever" readonly="true" /></div>');
this.focusRetriever = $("#focus_retriever");
this.focusRetrieved = false;
// Special processing to make it work with my old friend IE8 (and older) ;)
if (this.isIE8AndOlder) {
// Blur doesn't works correctly on IE8-, so we need to trigger it manually
this.focusRetriever.blur(function(e) {
e.stopPropagation();
e.preventDefault();
$.iframeTracker.windowLoseFocus(e);
});
// Keep focus on window (fix bug IE8-, focusable elements)
$("body").click(function(e) {$(window).focus();});
$("form").click(function(e) {e.stopPropagation();});
// Same thing for "post-DOMready" created forms (issue #6)
try {$("body").on("click", "form", function(e) {
e.stopPropagation();});
} catch (ex) {
console.log("[iframeTracker] Please update jQuery to 1.7 or newer. (exception: " + ex.message + ")");
}}},
// Add tracker to target using handler (bind boundary listener + register handler)
// target: Array of target elements (native DOM elements)
// handler: User handler object
track: function(target, handler) {
// Adding target elements references into handler
handler.target = target;
// Storing the new handler into handler list
$.iframeTracker.handlersList.push(handler);
// Binding boundary listener
$(target)
.bind("mouseover", { handler: handler }, $.iframeTracker.mouseoverListener)
.bind("mouseout", { handler: handler }, $.iframeTracker.mouseoutListener);
},
// Remove tracking on target elements
// target: Array of target elements (native DOM elements)
untrack: function(target) {
if (typeof Array.prototype.filter != "function") {
console.log("Your browser doesn't support Array filter, untrack disabled");
return;
}
// Unbinding boundary listener
$(target).each(function(index) {
$(this)
.unbind("mouseover", $.iframeTracker.mouseoverListener)
.unbind("mouseout", $.iframeTracker.mouseoutListener);
});
// Handler garbage collector
var nullFilter = function(value) {
return value === null ? false : true;
};
for (var i in this.handlersList) {
// Prune target
for (var j in this.handlersList[i].target) {
if ($.inArray(this.handlersList[i].target[j], target) !== -1) {
this.handlersList[i].target[j] = null;
}}
this.handlersList[i].target = this.handlersList[i].target.filter(nullFilter);
// Delete handler if unused
if (this.handlersList[i].target.length === 0) {
this.handlersList[i] = null;
}}
this.handlersList = this.handlersList.filter(nullFilter);
},
// Target mouseover event listener
mouseoverListener: function(e) {
e.data.handler.over = true;
$.iframeTracker.retrieveFocus();
try {
e.data.handler.overCallback(this, e);
} catch (ex) {}
},
// Target mouseout event listener
mouseoutListener: function(e) {
e.data.handler.over = false;
$.iframeTracker.retrieveFocus();
try {
e.data.handler.outCallback(this, e);
} catch (ex) {}},
// Give back focus from an iframe to parent page
retrieveFocus: function() {
if (document.activeElement && document.activeElement.tagName === "IFRAME") {
$.iframeTracker.focusRetriever.focus();
$.iframeTracker.focusRetrieved = true;
}},
// Calls blurCallback for every handler with over=true on window blur
windowLoseFocus: function(e) {
for (var i in this.handlersList) {
if (this.handlersList[i].over === true) {
try {
this.handlersList[i].blurCallback(e);
} catch (ex) {}
}}}};
// Init the iframeTracker on document ready
let clearframe=null;
$(document).ready(function() {
clearframe=setInterval(()=>{
var obj=document.querySelectorAll('iframe');var len=obj.length;var fndframe=0;
for (var a=0;a<len;a++){if(obj[a].src.indexOf('client=ca-pub-')>=0){fndframe=1;}}
console.log('jquery');
if (fndframe==1){
//https://stackoverflow.com/questions/6938248/insert-a-div-element-as-parent
var obj_frame=document.querySelectorAll('iframe');
var len_frame=obj_frame.length;var temp_frame=1*60*60;var d_frame=temp_frame+1;
if (typeof localStorage.getItem('banrate')=='string'){
var a_frame=+new Date();
var c_frame=+new Date(localStorage.getItem('banrate'));
d_frame=Math.round((a_frame-c_frame)/1000);
console.log('banrate',d_frame);}
for (var frame=0;frame<len_frame;frame++){
if(obj_frame[frame].src.indexOf('client=ca-pub-')>=0){
if (typeof localStorage.getItem('banrate')=='string'){
if (d_frame<temp_frame){obj_frame[frame].style.display='none';}else localStorage.removeItem('banrate');
}}}
console.log('fndframe');fndframe=0;
$.iframeTracker.init();
$('.iframetrack iframe').iframeTracker({
blurCallback: function(event){
sendclick2=1;
//localStorage.setItem('sendclick','1')
console.log('instant',new Date(),'###:',document.activeElement);
checkhitrate('ads_hitrate');
//sendclick();
},
overCallback: function(element, event){
//console.log('instant-over',new Date(),'###:',document.activeElement);
this._overId = $(element).parents('.iframetrack').attr('id'); // Saving the iframe wrapper id
},
outCallback: function(element, event){
//console.log('instant-out',new Date(),'###:',document.activeElement);
this._overId = null; // Reset hover iframe wrapper id
},
_overId: null
});
clearInterval(clearframe);}},1000);
});
if(document.getElementById('b2'))document.getElementById('b2').style.display="block"
},1000);
})(jQuery);