简体   繁体   中英

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?

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.

Perhaps there's some solution like:

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

which would set HTTP or HTTPs accordingly.

If that's impossible to set with just HTML, whats the best way to do it with javascript?

Thanks for help

Nearly there :)

it's

//www.mysite.com/form/post

More about protocol relative URLs

However, as @Petra mentioned, of course this makes sense only when the target is on a different domain. Otherwise, you would just use normal relative URLS: /form/post

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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