本地调试包含协议相关 URL 的网页的提示

发布于 2024-11-26 20:26:10 字数 331 浏览 5 评论 0原文

我想完成的任务可能有一个更好的标题,但细节应该会有所帮助。

我最近了解到将脚本的 src 路径指定为 //some.domain.com 而不是 http://some.domain.com > 或 https://some.domain.com 将导致浏览器使用用于加载页面的协议来请求脚本。当从站点加载页面时,这非常有效,但我经常在本地系统上进行调试,因此协议是 file,当然,只要找不到资源或脚本,就会发生错误。

除了更改src路径之外,还有更好的本地调试方法吗?我想有一个代码解决方案可以检测页面何时在本地运行以及何时从域加载,但我还没有找到示例。

There is probably a better title for I'd like to accomplish, but the details should be helpful.

I've recently learned that specifying a script's src path as //some.domain.com rather than http://some.domain.com or https://some.domain.com will cause the browser to request the script using whichever protocol was used to load the page. This works great when the page is loaded from a site, but often I debug on my local system, so the protocol is file, and of course errors occur whenever resources or scripts aren't found.

Other than changing src paths, is there a better way to debug locally? I imagine there is code solution that detects when the page is running locally versus loaded from a domain, but I haven't found examples yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你的星星会说话 2024-12-03 20:26:10

安装诸如 wampserver 之类的产品,然后您将拥有一个可以测试所有内容的本地主机网络服务器。我就是这样做的,就像魅力一样。

有类似的产品可用于 ASP 或其他非 PHP 服务器端技术(您没有指定),如果您只是做 HTML + JS 那么任何旧服务器都可以。

Install a product such as wampserver, then you'll have a localhost webserver you can test everything on. This is how I do it, works like a charm.

There are similar products available for ASP or other non-PHP server-side technologies (you didn't specify), if you are just doing HTML + JS then any old server would do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文