如何将存储在浏览器本地存储中的值传递给浏览器发起的请求?

时间:2017-09-12 12:36:45

标签: javascript

我在浏览器本地存储中存储了值

Demo

我如何在自定义请求标头中传递'value-x'? [使用Javascript] 例如,需要通过图像请求传递存储的值。

window.localStroage.setItem(key,'value-x');

如何在'some / url'请求中设置带有'value-x'的自定义标头(由浏览器启动)?

1 个答案:

答案 0 :(得分:0)

You can't.

The only time you can set an HTTP header programmatically is when you are making a request from JavaScript via XMLHttpRequest or fetch. There's no way to do it when the request is made by the insertion of an <img> element.

The closest you could come here would be to make the request using XHR, convert the response into a data: scheme URI, and then populate the src attribute with that.