The iframe
markup should not be inside your JavaScript
function. That does nothing except throwing an exception. Put the markup below your anchor and change its src
on click:
<a href="http://www.google.com" onclick="executeOnClick(this)">Google</a>
<iframe id="targetFrame"></iframe>
<script>
function executeOnClick(target) {
document.getElementById("targetFrame").src = target.src;
return false;
}
</script>
In fact you don't even need JavaScript
to do this. You can use the target
attribute of the anchor and set it to be the name of the frame you want to open the page in:
<a href="http://www.google.com" target="targetFrame">Google</a>
<iframe name="targetFrame" id="targetFrame"></iframe>