我尝试将Google ReCaptcha脚本插入页面,但我无法选择全局grecaptcha
。
val script = dom.document.createElement("script").asInstanceOf[HTMLScriptElement]
script.setAttribute("src", "https://www.google.com/recaptcha/api.js")
script.setAttribute("async", "true")
script.onload = { (_: Event) =>
println(Dynamic.global.selectDynamic("grecaptcha")) // --> got undefined
}
dom.document.body.appendChild(script)
在控制台窗口中,我可以获得grecaptcha
:
问题是如何选择全局grecaptcha
对象?
答案 0 :(得分:0)
根据this answer in a vanilla JavaScript environment,您只是有一个订购问题。步骤应该是
onload
事件src
属性val script = dom.document.createElement("script").asInstanceOf[HTMLScriptElement]
dom.document.body.appendChild(script)
script.onload = { (_: Event) =>
println(Dynamic.global.selectDynamic("grecaptcha"))
}
script.setAttribute("src", "https://www.google.com/recaptcha/api.js")
script.setAttribute("async", "true")