【问题标题】:nedd to pass html parameter to iframenedd 将 html 参数传递给 iframe
【发布时间】:2016-09-11 15:49:45
【问题描述】:

我有一个带有参数的页面: http://example.com/mypage.html?param=123

在 html 中,我有一个需要该参数的 iframe,如下所示:

现在我知道如何从 url 解析参数了,我可以在 onload() 中更改 iframe 的 src。但问题是 iframe 首先显示 w/o 参数(显示一些默认 iframe),然后在加载后它会正确显示。

我可以在加载时显示带有已解析参数的 iframe 吗? (没有 php,只有 javascript)

【问题讨论】:

标签: javascript html iframe


【解决方案1】:

看起来解决方案是像这样在正文中添加javascript:

<script>
    var sid = location.search.substr(location.search.indexOf("sid=")+4);
    var ifrm = document.getElementById('myiframe') ;
    var target = "http://example.com/myApp?sid=" + sid;
        ifrm.setAttribute('src', target);       
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-08
    • 2015-07-23
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多