Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript nedd将html参数传递给iframe_Javascript_Html_Iframe - Fatal编程技术网

Javascript nedd将html参数传递给iframe

Javascript nedd将html参数传递给iframe,javascript,html,iframe,Javascript,Html,Iframe,我有一个带有参数的页面: 在html中,我有一个需要该参数的iframe,类似于: 现在我知道如何从url解析参数,并且可以在onload()中更改iframe的src。但问题是iframe is首先不显示参数(显示一些默认iframe),然后在onload后将正确显示 我可以在加载时显示带有解析参数的iframe吗? (没有php,只有javascript)看起来解决方案是在主体中添加javascript,如下所示: <script> var sid = locatio

我有一个带有参数的页面:

在html中,我有一个需要该参数的iframe,类似于:

现在我知道如何从url解析参数,并且可以在onload()中更改iframe的src。但问题是iframe is首先不显示参数(显示一些默认iframe),然后在onload后将正确显示

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

看起来解决方案是在主体中添加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>

var sid=location.search.substr(location.search.indexOf(“sid=”)+4);
var ifrm=document.getElementById('myiframe');
变量目标=”http://example.com/myApp?sid=“+sid;
ifrm.setAttribute('src',target);

可能的副本不是上述副本。