Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:54:13+00:00 2026-06-13T19:54:13+00:00

I want to construct URLs with the same scheme (presumably, http: or https:) as

  • 0

I want to construct URLs with the same scheme (presumably, “http:” or “https:”) as the page that loaded the currently-running JavaScript. Modern browsers support simply omitting the scheme (for example, src="//example.com/test.js"), but this isn’t fully cross-browser compatible. (I’ve read that IE 6 is the only browser that doesn’t support it, but I still need compatibility with that version.)

The cross-browser way to do this seems to be to check location.protocol. For example, Google Analytics uses:

('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + ...

In Google’s case, they wanted to use different domains depending on whether the request uses SSL, so that pattern makes sense. But I’ve seen others use the same pattern even when only the protocol is different:

('https:' == location.protocol ? 'https:' : 'http:') + "//example.com"

(One example is in the “Final Wufoo Snippet” at http://css-tricks.com/thinking-async/.)

I’d prefer to use this simpler expression instead:

location.protocol + "//example.com"

Should I really be concerned about the possibility of location.protocol taking on some value other than “https:” or “http:” when my code is used on sites I don’t control?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:54:14+00:00Added an answer on June 13, 2026 at 7:54 pm

    It will always be set to something, but it may sometimes be set to a value that is neither “http” or “https”. The three other values you’re most likely to see are file: (for HTML files), about: (for iframe magic involving about:blank), and perhaps ftp:.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to realize a construct in MS SQL that would look like this
I want to construct a macro that, given a symbol 'foo , creates a
I want to construct an array of 3 offers that output in a random
I want to construct a timeline that has horizontal scrolling. I have a wrapper
I want to construct a transact sql script that will stop specified people from
I want to construct a url within my rails app that points to another
I want to construct a regular expression that will, for every line of text
I want to construct a div that has a header with background like that
I want to construct a program do the statistic page view base on Cassandra
I want to construct a context menu with a menu item for selecting a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.