调用JS链接;属性使用"onclick"事件

Calling JS "link" attribute using "onclick" event

本文关键字:quot onclick 事件 JS 链接 属性 调用      更新时间:2023-09-26

代码已更新

我试图改变我所有的硬编码链接到一个属性使用Onclick事件,所以它很容易让我通过改变只是在头部的属性来改变它们。链接在iframe中打开。

这是我现有的链接。它同时做两件事:

  1. 在新窗口中打开一些外部网页
  2. 调用另一个外部网页到我的页面。

我有很多这样的链接,我想使用一个脚本,将保持只是Onclick参数和iFrame名称,而不是写他们一遍又一遍。HREF链接应该保持原样。

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

<iframe id="MyFrame" frameborder="0" scrolling="no" width="5px" height="5px"></iframe>
所以实际上我想把上面的代码改成这样:
<script type="text/javascript">
            function Link() {
                document.getElementById("MyFrame").href = "iframe_source_url";
            }
    </script>

<a href="www.SomeWebsiteInaNewWindow.com" 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>

很抱歉给您带来麻烦,再次感谢。我是新来的……

你会想这样做的

<a href="http://www.example.com" onClick="window.open(this.href)" target="iframe_test">Test</a>
<iframe id="iframeid" name="iframe_test" frameborder="0" scrolling="no" width="300px" height="300px"></iframe>