use*_*974 3 html javascript blob parameter-passing
说我有一个参考的html文件的斑点 b和我创建一个URL它,url = URL.createObjectURL(b);.
这给了我一些看起来像的东西 blob:http%3A//example.com/a0440b61-4850-4568-b6d1-329bae4a3276
然后我尝试<iframe>使用GET参数打开?foo=bar它,但它不起作用.我怎样才能传递参数?
var html ='<html><head><title>Foo</title></head><body><script>document.body.textContent = window.location.search<\/script></body></html>',
b = new Blob([html], {type: 'text/html'}),
url = URL.createObjectURL(b),
ifrm = document.createElement('iframe');
ifrm.src = url + '?foo=bar';
document.body.appendChild(ifrm);
// expect to see ?foo=bar in <iframe>
Run Code Online (Sandbox Code Playgroud)
我不认为向URL添加查询字符串将起作用,因为它实际上将其更改为不同的URL.
但是,如果您只想传递参数,则可以使用散列将片段添加到URL
ifrm.src = url + '#foo=bar';
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/thpf584n/1/