使用Javascript在iframe中导航网址

Use*_*ser 9 html javascript iframe

我有这个代码,用iframe中的javascript导航URL,但它不起作用.为什么?

例如,我想site.com在单击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> 
Run Code Online (Sandbox Code Playgroud)

noo*_*oob 17

简单的HTML:

<a target="DBox" href="http://site.com">link1</a>
Run Code Online (Sandbox Code Playgroud)

或者只需使用JavaScript调用:

window.open("http://site.com", "DBox");
Run Code Online (Sandbox Code Playgroud)

  • 对不起,我现在也添加了一个JavaScript解决方案. (2认同)
  • 感谢你.`window.open("http://site.com","DBox");`解决了问题. (2认同)