Ciao a tutti.
Ho una pagina con un campo di testo, un bottone ed un iFrame.
Questo è il codice :
codice:
<html>
<head>
<title>Pagina di prova</title>
</head>
<body id="idBody" >
<script language="javascript" >
function openUri()
{
newUri = textInputObj.value;
iFrameObj.setAttribute("src", newUri);
}
bodyObj = document.getElementById("idBody");
textInputObj = document.createElement("input");
textInputObj.setAttribute("type", "text");
textInputObj.setAttribute("size", "40");
buttonOk = document.createElement("button");
buttonOk.appendChild(document.createTextNode("OK"));
buttonOk.addEventListener("click", openUri, false);
bodyObj.appendChild(document.createTextNode("URI : "));
bodyObj.appendChild(textInputObj);
bodyObj.appendChild(buttonOk);
iFrameObj = document.createElement("iframe");
iFrameObj.setAttribute("width", "98%");
iFrameObj.setAttribute("height", "100%");
iFrameObj.style.setProperty("position", "absolute", null);
iFrameObj.style.setProperty("top", 60, null);
iFrameObj.style.setProperty("left", "1%", null);
bodyObj.appendChild(iFrameObj);
</script>
</body>
</html>
Nel campo di testo digito una URI poi cliccando sul bottone viene
visualizzato il sito desiderato nell'iFrame.
Vorrei però gestire l'evento "onclick" del contenuto dell'iFrame, ma non so come fare.
Ho provato ad associarlo all'oggetto iFrameObj (iFrameObj.addEventListener) ma in questo caso riesco a catturarlo solamente se clicco sul bordo dell'iFrame.
Sapete aiutarmi? grazie.