Javascript
function prepareFrame() {
if (document.incluir.balancete_arquivo.value != ""){
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "<%=BARRASTATUS%>");
ifrm.style.width = "400px";
ifrm.style.height = "150px";
document.body.appendChild(ifrm);
}
}
HTML
<button type="button" onclick="prepareFrame()">Criar iframe</button>
To create iframe in exact location:
function prepareFrame() {
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "radioalfa2233.htm");
ifrm.style.width = "400px";
ifrm.style.height = "150px";
//o iframe será criado antes da div de id = divqq
var divReferencia = document.getElementById("divqq");
// adiciona o novo elemento criado e seu conteúdo ao DOM
document.body.insertBefore(ifrm, divReferencia);
}
and in HTML insert this div <div id="divqq"></div>
at the exact place where the iframe should be created
In case you want to hide the button after clicked
add this line inside the if
in the script
document.getElementById('bt').style.display = 'none';
and the id on the button <button id="bt"....
- The function
createElement()
create an HTML element to insert into an HTML document
- Apparently, the function
createElement()
it has no effect, we need to apply the method appendChild()
so that the element is effectively inserted into the HTML document and is visible to the user.
The question is unclear because an iframe can be inserted anywhere on the page.
– Sam
So, no matter where the page is, I just want instead of this so-called window.open('<%=BARRASTATUS%>','upload','width=400,height=150');, to pull an iframe, so maybe upload.html
– Samuel Neto
But an iframe is an HTML tag that should be inserted on the page. Where?!
– Sam
On the same page of the call the script.
– Samuel Neto
That I know, buddy. But where on the page? At the beginning, at the end, hidden, like a modal, in the middle, after some specific element etc etc... that’s what’s vague in the question.
– Sam
This, the iframe will be placed at the bottom of the page, when clicked the button it will appear.
– Samuel Neto
Welcome Samuel Neto, consider scheduling an answer that best met your acceptance. See how in https://i.stack.Imgur.com/evLUR.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252