Jonathan
Jonathan

Reputation: 3457

What does // mean in an <a> tag

I'm writing a web crawler and I'm testing it out by starting at Wikipedia. However, I noticed that many of wikipedia's links are prefaced with //, so the link from wikipedia.org to en.wikipedia.org is a link to //en.wikipedia.org. What exactly does this // mean in practice? Does it say "use whatever scheme you were using before and then redirect to this url?" or does it mean something entirely different?

Upvotes: 3

Views: 182

Answers (4)

Lajos Veres
Lajos Veres

Reputation: 13725

It is protocoll relative url. It keeps http or https.

Upvotes: 1

geomagas
geomagas

Reputation: 3280

Yes, it will redirect to that url using the scheme of the current location.

In order for this to work, the resource this url points to must be available in every scheme it's expected to be redirected from (usually, both http and https).

Upvotes: 1

digao_mb
digao_mb

Reputation: 1294

It maintains the protocol that is being used for the webpage. HTTP/HTTPS.

It's particulaly useful for external scripts and css tags, in which you don't know in which protocol your site will be working on.

That's why on Google libraries (https://developers.google.com/speed/libraries/devguide#jquery) you have like this:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

Just while writing this I found a duplicate: Two forward slashes in a url/src/href attribute

Take a look at it.

Upvotes: 2

iPao
iPao

Reputation: 1163

The link will use protocol (http or https) same as page which contain that link. For example if https://stackoverflow.com/ contain <a href="//en.wikipedia.org"></a> it will directed to https://en.wikipedia.org

Upvotes: 4

Related Questions