Guy Guy - 10 months ago 32
Javascript Question

Calling JS "link" attribute using "onclick" event

Code has been updated.

I'm trying to change all my hard coded links into a one attribute using Onclick event, so it would easy to me to change them all by changing just the attribute at the Head. The link is opened in an iframe.

This is my existing link. It does two things simultaneously:

  1. Open some external webpage in a new window.

  2. Calling another external webpage into my page.

I have many links like this, and I would like to use a script that will hold just the Onclick parameters and the iFrame name, instead of writing them again and again. The HREF link should be stay as is.

<a href="" rel="nofollow" target="_blank" onClick=document.getElementById("MyFrame").src='www.CallingThe';>A link that execute both Href & Onclick</a>

<iframe id="MyFrame" frameborder="0" scrolling="no" width="5px" height="5px"></iframe>

So actually I would like to change the above code, to something like this:

<script type="text/javascript">

function Link() {
document.getElementById("MyFrame").href = "iframe_source_url";

<a href="" target="_blank" onClick="take a url value from above into MyFrame">A link that execute both Href & Onclick based of the values that will be taken from the above head script</a>

Sorry for the hassle, and thanks again very much.
I'm new here...

Answer Source

You would want to do something like that

<a href="" onClick="" target="iframe_test">Test</a>

<iframe id="iframeid" name="iframe_test" frameborder="0" scrolling="no" width="300px" height="300px"></iframe>