将参数传递给BLOB对象URL [英] Pass parameter to BLOB object URL

查看:248
本文介绍了将参数传递给BLOB对象URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Say I've got a reference to a html file as a Blob b and I create a URL for it, url = URL.createObjectURL(b);.

这使我看起来像blob:http%3A//example.com/a0440b61-4850-4568-b6d1-329bae4a3276

然后我尝试使用 GET 参数?foo=bar<iframe>中打开此文件,但是没有用.如何传递参数?

I then tried opening this in an <iframe> with a GET parameter ?foo=bar, but it didn't work. How can I pass the parameter?

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>

演示

推荐答案

我认为向该网址添加查询字符串不会起作用,因为它实际上会将其更改为其他网址.
但是,如果您只想传递参数,则可以使用哈希将片段添加到url

I don't think adding a query string to the url will work as it essentially changes it to a different url.
However if you simply want to pass parameters you can use the hash to add a fragment to the url

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

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

这篇关于将参数传递给BLOB对象URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆