简体   繁体   English

禁用复选框,直到 iframe 滚动

[英]Disabling a checkbox until an iframe has scrolled

I suspect this is probably not possible due to browser security, however I have a form at the end of which is an iframe displaying our terms and conditions page.我怀疑由于浏览器的安全性,这可能是不可能的,但是我有一个表格,最后是一个 iframe 显示我们的条款和条件页面。 Below is a checkbox for agreeing to these terms and conditions.以下是同意这些条款和条件的复选框。

Other sites I have seen require you to scroll down in the terms and conditions before the checkbox is active but i suspect this is done with a textarea or scrollable div rather than an iframe.我见过的其他网站要求您在复选框处于活动状态之前向下滚动条款和条件,但我怀疑这是通过 textarea 或可滚动 div 而不是 iframe 完成的。

As such is anyone aware of how you can spot when an iframe has scrolled in javascript or jQuery so I can enable the checkbox once it has been scrolled.因此,任何人都知道如何发现 iframe 在 javascript 或 jQuery 中滚动时如何发现,以便在滚动复选框后启用该复选框。

Following code in your embedded document should do it.嵌入文档中的以下代码应该可以做到。

 $(window).scroll(function () {
            if ($(document).height() <= $(window).height() + $(window).scrollTop())
                $("#chk", window.parent.document).removeAttr("disabled");
 });

I have not seen a check box automatically become active after scrolling, and actually cannot see the purpose of it.我没有看到滚动后自动激活复选框,实际上看不到它的用途。 What difference does it make if the checkbox is active or not when it's hidden?如果复选框在隐藏时处于活动状态,它有什么区别?

I would also add that I may have misunderstood your question.我还要补充一点,我可能误解了你的问题。 Do you want the checkbox to become selected after scroll?您希望复选框在滚动后被选中吗? Again this would be pretty dangerous because you could find that your users end up agreeing to your terms by default because of the code that you are about to write.同样,这将非常危险,因为您可能会发现您的用户最终默认同意您的条款,因为您将要编写代码。

Having said all that what you are asking may be answered in the question I asked a while ago here说了这么多你所问的可能会在我刚才在这里问的问题中得到回答

I'm not sure you can do that (but I'm not sure you can't).我不确定你能做到这一点(但我不确定你不能)。 Here is an alternate solution for you:这是您的替代解决方案:

Simply put the checkbox in your iframe .只需将checkbox放在您的iframe中。 The user will only see it when having scrolled down the iframe .用户只有在向下滚动iframe时才能看到它。

Hint: you can also put everything in a div with fixed size and overflow-y:scroll in your CSS.提示:您还可以将所有内容放在 CSS 中具有固定大小和overflow-y:scrolldiv中。 Doing this, the checkbox will be in your page.这样做, checkbox将出现在您的页面中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM