所以我有一个按钮可以将页面转发到像 example.tk 这样的网站,但它一直认为我只想转到它所在的网站文件夹内的 ./example.tk。
我尝试过 window.location、window.location.replace、window.location.href、 和 self 定位。
myButton.addEventListener('click', function() {
window.location.href = "example.tk";
});
我希望网站从 url 更改为 example.tk,如果 example.tk 没有经过认证的 https 标签,我该怎么做?
最佳答案
I want the website to change from the url it is to example.tk, how would I do that if the example.tk does not have a certified https tag?
不太清楚你的意思。如果您的意思是要从 http://
资源链接到 https://
资源,请明确说明:
window.location.href = "http://example.tk";
// ---------------------^^^^^^^
如果您想要使用与当前页面相同的协议(protocol)(http:
或 https
),您可以使用协议(protocol)相对 URL :
window.location.href = "//example.tk";
// ---------------------^^
这将使用当前页面的协议(protocol)。在 http://example.com
上,它将链接到 http://example.tk
。在 https://example.com
上,它将链接到 https://example.tk
。
将鼠标悬停在此代码段中的链接即可查看其运行情况(无需单击):
<a href="//example.tk">hover this link</a>
关于javascript - 如果网站无法使用 "https://",如何在 Javascript 中转发我的页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56296132/