最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - linking from OnClick to iframe - Stack Overflow

programmeradmin0浏览0评论

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:

<a href="#" onClick="window.open('');return false">Google</a>

But when it es to Iframes I am having difficulty formatting the code correctly so that it will display inside the iframe.

I can not use:

<a href="" target="your_frame_name">Google</a>

Because I need to use an onClick so I can execute more than one mand.

I have tried iterations of:

<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="document.framename.location.href='page.htm'; return false">text</a>

and none of them are doing anything.

Thank you in advance,

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:

<a href="#" onClick="window.open('http://www.google.');return false">Google</a>

But when it es to Iframes I am having difficulty formatting the code correctly so that it will display inside the iframe.

I can not use:

<a href="http://www.google." target="your_frame_name">Google</a>

Because I need to use an onClick so I can execute more than one mand.

I have tried iterations of:

<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="document.framename.location.href='page.htm'; return false">text</a>

and none of them are doing anything.

Thank you in advance,

Spence

Share Improve this question asked Apr 18, 2011 at 16:04 SpenceSpence 1251 gold badge1 silver badge10 bronze badges 1
  • 1 give an id to your iframe and find it by getElementById then assign its src. – Naren Sisodiya Commented Apr 18, 2011 at 16:07
Add a ment  | 

1 Answer 1

Reset to default 1

use link and do what ever you want to do in onclick event

<a href="http://www.google." target="your_frame_name" onclick="executeOnClick()">Google</a>

<script type="text/javascript">
function executeOnClick(){

// add your logic here


return true;
}
</script> 
发布评论

评论列表(0)

  1. 暂无评论