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

html - Navigate URL in iframe with Javascript - Stack Overflow

programmeradmin4浏览0评论

I have this code, to navigate a URL with javascript in an iframe, but it does not work. Why?

For example, I want navigate to site when I click link1.

<script language="javascript">
function nav()
{
window.navigate('',target="DBox");
}   
</script>   


<a href="javascript:nav();">link1</a>

<iframe name="DBox" src="http://example" frameborder="0" style="width:100%;height:100%"></iframe> 

I have this code, to navigate a URL with javascript in an iframe, but it does not work. Why?

For example, I want navigate to site.com when I click link1.

<script language="javascript">
function nav()
{
window.navigate('http://site.com',target="DBox");
}   
</script>   


<a href="javascript:nav();">link1</a>

<iframe name="DBox" src="http://example" frameborder="0" style="width:100%;height:100%"></iframe> 
Share Improve this question edited Sep 11, 2013 at 15:20 123 5251 gold badge5 silver badges20 bronze badges asked Jan 2, 2012 at 14:57 returnreturn 1,0495 gold badges17 silver badges28 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 18

Simple HTML:

<a target="DBox" href="http://site.com">link1</a>

Or with just call this with JavaScript:

window.open("http://site.com", "DBox");

This will be navigate to url in the same window.

window.top.location.href = "http://example.com";
发布评论

评论列表(0)

  1. 暂无评论