javascript - 如果网站无法使用 "https://",如何在 Javascript 中转发我的页面?

标签 javascript html url https forward

所以我有一个按钮可以将页面转发到像 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/

相关文章:

javascript - jquery中如何获取$(this)的特定上层类

javascript - ASP.NET : use the Text property as selector to jQuery event

javascript - 如何使用 HTML、CSS 和 JS 制作基于音频标签的自定义音乐播放器

angularjs - 如何在 URL 中排序过滤器而不将它们放在键值中

php - Jquery从URL加载数据或转到URL

javascript - Javascript 中的对象属性和对象属性有什么区别?

javascript - 如何从本地存储重新加载 jstree?

iPhone HTML5 功能支持

html - 在 Bootstrap 框的中心对齐文本和图标

url - 当方案没有双斜杠时无法抓取 NSURL 组件