开发者

Open a secured URL containing a pdf file using javascript in safari by passing username and password

I have a webpage where i show a list of links pointing to pdf files. These links are https links, which require username.password to access the link. My requirement is that when i click on the link.. it should open the pdf file referred by link in an iframe, without asking for username.password? right now when i click on the URL it first shows me a prompt to enter username/password and then open开发者_如何学编程s the pdf file in the same page itself.

please help me with this?


That authentication mechanism sounds like plain HTTP authentication. http://example.com and https://example.com are considered different domains. If you've authenticated before on http://example.com, you need to re-authenticate for https://example.com. If this is the case, the solution is simple: either use https://example.com for everything or stick to http://example.com.

If the username/ password combination is not really sensitive, you could pass it to the URL as well:

https://user:pass@example.com/your-document.ext

Note that modern browsers will probably ask you whether you want to login with the given credentials before opening the link.

The above behavior is not dependent on Javascript. If you want to force https on your page with Javascript, use:

<script>
if (location.protocol == "http:") {
    location.href = location.href.replace(/^http/, "https");
}
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜