我使用的是js图库(photoswipe),其中一张幻灯片不是图像,但有一些html。
幻灯片中是用onmousedown提交表单上的事件跟踪,我无法使用它。
所以我有:
some vars
items.push({ html: '<div and form start etc>
<input type="submit" onmousedown="javascript:_paq.push(["trackEvent" etc ]);_paq.push(["etc"]);_paq.push(["etc"]);">
'});我已经从摆弄和试错中学到了很多,很抱歉这个新手的问题。
有没有人有主意?
发布于 2019-06-22 22:00:14
以这种方式注入JS并不是最干净的做法。相反,您可以考虑使用事件委派的更全局的方法:
在页面中的某个位置,包含一个单击侦听器:
document.addEventListener('click', function (event) {
if(event.target.classList.contains('js-track-subscribe-blog-location')) {
_paq.push(["trackEvent","Blog","Subscribe",location.pathname.substring(1)])
}
})从运行此脚本的那一刻起,页面上任何包含js-track-subscribe-blog-location类的内容都将在单击时触发跟踪代码。
只需在你的<input type="submit"中包含这个类,它就可以工作了。
https://stackoverflow.com/questions/56715814
复制相似问题