【问题标题】:Navigate URL in iframe with Javascript使用 Javascript 在 iframe 中导航 URL
【发布时间】:2012-01-02 14:57:45
【问题描述】:

我有这段代码,可以在 iframe 中使用 javascript 导航 URL,但它不起作用。为什么?

例如,我想在单击链接 1 时导航到 site.com

<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> 

【问题讨论】:

    标签: javascript html iframe


    【解决方案1】:

    简单的 HTML:

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

    或者只用 JavaScript 调用它:

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

    【讨论】:

    • 我想用javascript 导航 URL。这段代码不适合我的问题! :)
    • 抱歉,我现在也添加了一个使用 JavaScript 的解决方案。
    【解决方案2】:

    这将导航到同一窗口中的 url。

    window.top.location.href = "http://example.com";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 2017-06-14
      • 2010-12-02
      • 1970-01-01
      • 2019-03-16
      • 2014-10-24
      • 2021-10-24
      相关资源
      最近更新 更多