Javascript 加载之前链接点击(问题)
我将 Shadowbox 用于一些 html/iframe 链接,这可以有效地在灯箱中打开页面。一切都运行良好 - 除非有人在 javascript 加载完成之前点击。
现在,显而易见的答案是不要使用链接作为加载 Shadowbox 的目标。但如果禁用 javascript,这会带来可用性问题。有谁对如何解决该问题有任何想法?我正在考虑加载内联 javascript,这将停用链接,直到页面加载完成,尽管我不太确定如何实现这一点。
欢迎所有想法!
I'm using shadowbox for some html/iframe links, which effectively opens up the page in a lightbox. Everything works great - except when someone clicks before the javascript is done loading.
Now, the obvious answer is to not use links as the targets of loading the shadowbox. But this poses usability problems if javascript is disabled. Does anyone have any ideas on how else to solve the problem? I'm considering loading javascript inline that would deactivate the links until the page is done loading, although I'm not exactly sure how I'd approach that.
All ideas are welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,我认为这不是问题,但是你不能直接在链接之后调用内联的 Shadowbox 处理器吗?
即:
.link、.link、.link
脚本
$(".link").shadowbox();
/脚本
In general, I'd consider this to be a non-issue, but can't you just call the shadowbox processor inline directly after the links?
i.e.:
.link, .link, .link
script
$(".link").shadowbox();
/script
您可以将链接定义为
,然后在加载 JavaScript 后重新分配单击事件处理程序。或者,如果您的链接有非 JavaScript 替代方案:
同样,当您的 JavaScript 加载时,您可以添加单击事件处理程序并覆盖默认操作。
如果加载所有脚本需要一段时间,您可能会重新考虑是否需要立即加载所有脚本。如果这样做,那么您可以实现一个加载屏幕(下面的示例使用 jQuery,但不是必须的):
这样,在加载所有脚本之前,您的网站内容是不可见的。
You could define your links as
and then reassign the click event handler once your javascript is loaded. Or, if your links have non-JavaScript alternatives:
Again, when your JavaScript loads you can add a click event handler and override the default action.
If it takes a while for all of your scripts to load, you might reconsider if you need to load all of them right away. If you do, then you could implement a loading screen (below example uses jQuery, but it doesn't have to):
This way your site content isn't visible until all of your scripts are loaded.