javascript 从 OnClick 链接到 iframe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5705680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
linking from OnClick to iframe
提问by Spence
I am attempting to have a link load an article from my domain in to an iframe. I understand that it is usually easy to link using:
我正在尝试通过链接将我的域中的文章加载到 iframe 中。我知道使用以下链接通常很容易:
<a href="#" onClick="window.open('http://www.google.com');return false">Google</a>
<a href="#" onClick="window.open('http://www.google.com');return false">Google</a>
But when it comes to Iframes I am having difficulty formatting the code correctly so that it will display inside the iframe.
但是当涉及到 iframe 时,我很难正确格式化代码,以便它显示在 iframe 中。
I can not use:
我不能使用:
<a href="http://www.google.com" target="your_frame_name">Google</a>
<a href="http://www.google.com" target="your_frame_name">Google</a>
Because I need to use an onClick so I can execute more than one command.
因为我需要使用 onClick 以便我可以执行多个命令。
I have tried iterations of:
我尝试了以下迭代:
<A HREF="#" onclick="window.framename.location='page.htm';">text</A>
<A HREF="#" onclick="window.framename.location='page.htm';">text</A>
<A HREF="#" onClick="window.open('your url', 'frameName'); return false">text</a>
<A HREF="#" onClick="window.open('your url', 'frameName'); return false">text</a>
<A HREF="#" onclick="document.framename.location.href='page.htm'; return false">text</a>
<A HREF="#" onclick="document.framename.location.href='page.htm'; return false">text</a>
and none of them are doing anything.
他们都没有做任何事情。
Thank you in advance,
先感谢您,
Spence
斯宾塞
采纳答案by Naren Sisodiya
use link and do what ever you want to do in onclick event
使用链接并在 onclick 事件中做任何你想做的事情
<a href="http://www.google.com" target="your_frame_name" onclick="executeOnClick()">Google</a>
<script type="text/javascript">
function executeOnClick(){
// add your logic here
return true;
}
</script>