Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

javascript - 在window.open请求中添加标题的可能方法(Possible way to add headers in a window.open request)

This answer here says I can't pass headers while using window.open.

(这个答案在这里说,尽管使用window.open我不能通过头。)

Although I couldn't find any documentation stating this.

(尽管我找不到任何说明文件。)

Is it really not possible to do so.

(真的不可能这样做。)

Are there any possible hacks ?

(有没有可能的骇客?)

My client requests are sent to a server which I can't control.

(我的客户请求已发送到我无法控制的服务器。)

The request sent by browser for opening pdf ( window.open ) is received at that server without auth headers.

(浏览器发送的打开pdf( window.open )的请求在该服务器上收到,没有auth标头。)

Hence, user is prompted for username and password.

(因此,提示用户输入用户名和密码。)

Is there a way I can resolve my issue and be able to open pdf from my Angular application.

(有没有一种方法可以解决我的问题并能够从Angular应用程序中打开pdf。)

I would also like to know how window.open works internally as I could not find it online ?

(我也想知道window.open在内部如何工作,因为我无法在线找到它?)

Thanks in advance

(提前致谢)

  ask by Saurabh Tiwari translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was able to solve the problem by getting the file twice, once from the server and once from cache.

(我可以通过两次获取文件来解决问题,一次是从服务器,一次是从缓存。)

This required a Cache-Control header on the response.

(这需要响应上的Cache-Control标头。)

I'm working with Angular, AdalJS, and Web Api but this might apply more broadly.

(我正在使用Angular,AdalJS和Web Api,但这可能会更广泛地适用。)

I use a $http call with auth header added by AdalJS to securely retrieve the file.

(我使用带有AdalJS添加的auth标头的$ http调用来安全地检索文件。)

This response is cached by the browser.

(该响应由浏览器缓存。)

When complete, I use window.open to open the cached file.

(完成后,我使用window.open打开缓存的文件。)

Pop-up blocking can be a problem.

(弹出窗口阻止可能是个问题。)

If you can't disable blocking, consider displaying a second button to click when the download is complete, calling window.open from that.

(如果您不能禁用阻止功能,请考虑在下载完成后显示第二个按钮以单击,然后从中调用window.open。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...