Skip to content
Advertisement

Set iframe content to return value from fetch command

I would like to set the content of an iframe on my html page to the response from a fetch command in js. I am currently using this code.

JavaScript

When i test this code, the iframe just displays

JavaScript

I would like to see an embedded youtube video in the iframe.

Advertisement

Answer

data is promise object you need to await or another then

JavaScript

but there is another problem, the response headers doesn’t have Access-Control-Allow-Origin so you can’t read the response. and the mode: 'no-cors' wont bypass CORS.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement