Reputation: 95
window.addEventListener('load', () => {
window
.fetch('https://services.share-pi.aarp.org/applications/CoreServices/WSOWebService/captcha/getWidget')
.then((resp) => resp.text())
.then(data => {
// Initialize the DOM parser
var parser = new window.DOMParser()
// Parse the text
var doc = parser.parseFromString(data, 'text/html')
// Print to console
console.log(doc.documentElement)
document.getElementById('nuCaptcha').appendChild(doc.documentElement)
})
})
<h3>NuCaptcha</h3>
<div id="nuCaptcha" class=""></div>
I'm implementing a NuCaptcha - similar to Google Captcha.
I'm printing the response of my request into the console. When i paste this response into JSBin or a blank .html . file, it works and the captcha challenge displays but the captcha added to the page doesn't seem to be rendering.
Anyone have any ideas on why this is happening?
Upvotes: 0
Views: 111
Reputation: 163
The trick is to execute the scripts after pasting the downloaded html.
window.addEventListener('load', () => {
window.fetch('https://services.share-pi.aarp.org/applications/CoreServices/WSOWebService/captcha/getWidget').then((resp) => resp.text()).then(data => {
var div = document.getElementById('nuCaptcha');
div.innerHTML = data;
var script = div.getElementsByTagName('script')
for (var i = 0; i < script.length; i++) eval(script[i].innerHTML);
})
})
<h3>NuCaptcha</h3>
<div id="nuCaptcha" class=""></div>
Upvotes: 2