javascript - 将参数传递给 BLOB 对象 URL

标签 javascript html blob parameter-passing

假设我有一个 html 文件的引用作为 Blob b,我为它创建了一个 URL,url = URL.createObjectURL(b);

这给了我一些看起来像 blob:http%3A//example.com/a0440b61-4850-4568-b6d1-329bae4a3276 的东西

然后我尝试使用 GET 参数 <iframe>?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>

DEMO

最佳答案

我不认为向 url 添加查询字符串会起作用,因为它本质上会将它更改为不同的 url。
但是,如果您只是想传递参数,您可以使用哈希将片段添加到 url

ifrm.src = url + '#foo=bar';

http://jsfiddle.net/thpf584n/1/

关于javascript - 将参数传递给 BLOB 对象 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27581335/

相关文章:

javascript - Jquery - 如何在文档区域中选择具有相同类名的 2 个元素?

javascript - 如何在单独的组件中使用 url 参数

javascript - 表单正在清除空白输入上一组数据

javascript - bootstrap 中的按钮不起作用

php - 溢出 :scroll isn't working for php comment system

javascript - 在将文件写入客户端磁盘时从blob创建/对象URL释放内存

javascript - 尝试在 Protractor 中使用类时获取 "TypeError: Dropdown is not a function"

caching - 更新我的 Windows Azure 存储上的图片(刷新)

javascript - Chrome 65 更改为在 Chrome 应用中自动下载 blob

html - 正文中的 CSS 媒体查询