简体   繁体   English

HTTP或HTTPS(根据当前连接)

[英]HTTP or HTTPS according to current connection

Whats the best way to determine if user is on HTTP or HTTPS connection on specific page without usage of server-side dynamic language? 在不使用服务器端动态语言的情况下确定用户是通过特定页面上的HTTP还是HTTPS连接的最佳方法是什么?

I have a page with form, which posts to some URL and I would like that URL to be HTTP or HTTPS - according to current connection. 我有一个带有表单的页面,该页面张贴到一些URL,根据当前连接,我希望该URL是HTTP或HTTPS。

Perhaps there's some solution like: 也许有一些解决方案,例如:

<form action="://www.mysite/form/post" method="post">

which would set HTTP or HTTPs accordingly. 这将相应地设置HTTP或HTTP。

If that's impossible to set with just HTML, whats the best way to do it with javascript? 如果仅使用HTML无法设置,那么用javascript做到这一点的最佳方法是什么?

Thanks for help 感谢帮助

Nearly there :) 就快到了 :)

it's 它的

//www.mysite.com/form/post

More about protocol relative URLs 有关协议相对URL的更多信息

However, as @Petra mentioned, of course this makes sense only when the target is on a different domain. 但是,正如@Petra所述,仅当目标位于其他域时,这才有意义。 Otherwise, you would just use normal relative URLS: /form/post 否则,您将只使用普通的相对URL: /form/post

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM