I have an iframe that shows a page with a list of objects.
I have another page where the user can create new objects.
I would like to update the iframe content showing the list updated with the new object created.
controller.html
<html>
<script src="controller.js"></script>
<script src="iframe.js"></script>
<iframe id="iFrame" style="border: 1px solid black" src="http://myurl:3000/iframe.html" width="100%" height="300"
allowfullscreen sandbox="allow-scripts">
</iframe>
<button onclick="obj.create()">Create </button>
</html>
controller.js
//function that is called after the user has created a new object
getObjList(){
let iframe = document.getElementById('iFrame');
var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
var obj_list
var obj_message
if (iframeDocument) {
obj_list = iframeDocument.getElementById('obj_list');
obj_message = iframeDocument.getElementById('obj_message');
}
$.ajax({
type: "GET",
url: '/objects/iframe',
success: function success(answer) {
if (obj_list.innerHTML !== ""){
$('#obj_list').html("")
}
if (typeof answer === 'object') {
if (answer.message === 'ok'){
if (answer.result.length > 0){
obj_message.css('display', 'none');
obj_list.css('display', 'block');
for (let i=0; i<answer.result.length; i++){
obj_list.append(`
<div class="card" style="width: 20rem;">
<div class="card-body">
<h5 class="card-title">${answer.result[i].title}</h5>
<p class="card-text">Description: ${answer.result[i].desc}</p>
</div>
</div>`)
}
} else {
obj_message.css('display', 'block');
obj_list.css('display', 'none');
}
}
console.log(answer)
}
},
error: function error(error) {
console.log('nope, it didnt work', error)
}
});
iframe.html
<html>
<h2>LIST OF Obj - IFRAME </h2>
<!---OBJ CONTAINER LIST-->
<div id="obj_list">
</div>
<div id ="obj_message">
<p>There have not been created any objects</p>
</div>
</div>
</html>
The problem I am having is that I am not able to update the content inside the iframe.
I get this error:
Blocked a frame with origin “xxxxxx” from accessing a cross-origin frame
Is there a way I can achieve the update of the content of an iframe?
The content of the iframe is a page I manage, that later has to be embedded in another website.