函数调用不返回调用函数

发布于 2024-09-06 18:45:28 字数 818 浏览 6 评论 0原文

我正在使用 Shadowbox.js 在网站上显示幻灯片。 该幻灯片显示了几张图片,我想知道谁在看哪些图片。 为此,我使用 statcounter.com。 Shadowbox 提供了一个所谓的钩子,用于在幻灯片打开和更改为另一张图片时调用函数。 我已经编写了一小段代码来让事情进展顺利,但由于某种原因,我在统计计数器日志中得到了一个条目,但影子框没有出现。 当我在选项中不使用 onopen 和 onchange 时,阴影框会显示。 作为测试,您可以设置一个目录来放置下面的代码。在此目录中创建名为“sb”和“pix”的子目录。从网站获取 Shadowbox 应用程序并将其存储在“sb”目录中 (http://shadowbox- js.com/download.html)。 接下来,在“pix”目录中存储 3 个测试图像(称为 image1.jpg、image2.jpg 和 image3.jpg)。 要检查 statcounter 是否正在拾取图片,您可以使用 statcounter.com 上的我的 testaccount(仅用于查看:帐户 testcase,密码 casetest1)。

请在此处找到包含代码的 html: http://www.heres-online.nl /test/index.html

请考虑到,我才刚刚开始 JavaScript 和 html 编程。 我可以想象我正在忽略一些非常简单的事情...... 非常感谢任何帮助。

I'm using Shadowbox.js to display a slideshow on a website.
This slideshow shows several pictures and I would like to know who's looking at what pictures.
For this purpose I'm using statcounter.com.
Shadowbox offers a so called hook to call a function when the slideshow opens and when it changes to another picture.
I've written a small piece of code to get things moving, but for some reason, I get an entry in my statcounter log, but the shadowbox does not appear.
When I don't use the onopen and onchange in the options, the shadowbox does display.
As a test you can set up a directory where you place below code. Create to subdirs in this directory called "sb" and "pix". Get the Shadowbox-application from the website and store it in the "sb" directory (http://shadowbox-js.com/download.html).
Next to that store 3 testimages (called image1.jpg, image2.jpg and image3.jpg) in the "pix" directory.
To check if statcounter is picking up the pictures, you can use my testaccount on statcounter.com (just for viewing: account testcase, password casetest1).

Please find the html with the code here: http://www.heres-online.nl/test/index.html

Please take into account, I only just starting in javascript and html programming.
I can imagine I'm overlooking something terribly simple ...
Any help is highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舟遥客 2024-09-13 18:45:28

不要尝试以这种方式插入图像标签,只需制作一个:

var img = new Image();
img.src = "... tracker URL ...";

这就是您需要做的全部。 编辑 同时删除 URL 字符串中的所有反斜杠;他们没有任何意义。

再次编辑我认为这就是您所需要的:(

var nonsense = 1;
function tracker() {
  var img = new Image();
  img.src = "http://c.statcounter.com/counter.php?sc_project=5981755&security=582aa718&invisible=1&u=" +
    encodeURIComponent("http://my.pix/" + Shadowbox.getCurrent().content) +
    '&nonsense=' + new Date().getTime() + '_' + nonsense++);
  return true;
}

添加了一个“废话”参数来尝试克服可能的缓存问题)

编辑 - 好的注意“返回true”和将“escapeURIComponent”(错误)更改为“encodeURIComponent”。 (我总是感到困惑,因为旧的已弃用函数被称为“escape”。)

Instead of trying to insert an image tag that way, just make one:

var img = new Image();
img.src = "... tracker URL ...";

That's all you need to do. edit Also get rid of all those backslashes in your URL strings; there's no point to them.

edit again I think this is all you need:

var nonsense = 1;
function tracker() {
  var img = new Image();
  img.src = "http://c.statcounter.com/counter.php?sc_project=5981755&security=582aa718&invisible=1&u=" +
    encodeURIComponent("http://my.pix/" + Shadowbox.getCurrent().content) +
    '&nonsense=' + new Date().getTime() + '_' + nonsense++);
  return true;
}

(added a "nonsense" parameter to try and overcome possible caching issues)

edits — OK note the "return true" and the change of "escapeURIComponent" (wrong) to "encodeURIComponent". (I always get confused because the old deprecated function was called "escape".)

过度放纵 2024-09-13 18:45:28

请对我最后的评论保持冷静。我自己也犯了一个错误(错别字)。
我输入的不是encodeURIComponent,而是enocdeURIComponent(为什么不复制/粘贴......是的,我只是没有)。
该脚本现在正在完全按照我的预期进行。我知道幻灯片中的每张图片都有一个统计计数器条目!高超。我对你的帮助感到非常满意,这真的让我很烦恼,无法让它运行。而且这里得到答案的速度实在是太惊人了!
我也在 Shadowbox.js 论坛上发布了您的解决方案。我也在那里发布了我的问题,但还没有答案。但对于遇到同样问题的任何人来说,这个解决方案可能会有所帮助。
再次感谢,祝周末愉快!

Please hold your horses on my last comment. I made a mistake myself (typo).
Instead of encodeURIComponent I typed enocdeURIComponent (why not copy/paste ... yeah, well I just didn't).
The script is now doing exactly what I intended it to do. I know have a Statcounter entry for every picture in the slideshow! Superb. I'm very pleased with your help, this was really nagging me, not being able to get it running. And the speed of getting an answer here was really amazing!
I've posted your solution on the Shadowbox.js forum as well. I posted my question there too, but no answers yet. But for anyone strugling with the same issue, this solution might be helpfull.
Thanks again, and have a nice weekend!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文