URL Info

S

Samuel Shulman

Hi

I need to retrieve the domain part of the url from the current page

How do I do that?

Thank you,
Samuel
 
E

Evertjan.

Samuel Shulman wrote on 25 sep 2007 in comp.lang.javascript:
Hi

I need to retrieve the domain part of the url from the current page

var r = window.location.href.replace(/[^\/]*\/\/([^\/]*).*/,'$1')
 
P

pr

Evertjan. said:
Samuel Shulman wrote on 25 sep 2007 in comp.lang.javascript:
I need to retrieve the domain part of the url from the current page

var r = window.location.href.replace(/[^\/]*\/\/([^\/]*).*/,'$1')

not window.location.host ?
 
E

Evertjan.

pr wrote on 25 sep 2007 in comp.lang.javascript:
Evertjan. said:
Samuel Shulman wrote on 25 sep 2007 in comp.lang.javascript:
I need to retrieve the domain part of the url from the current page

var r = window.location.href.replace(/[^\/]*\/\/([^\/]*).*/,'$1')

not window.location.host ?

Did I say that?
 
T

Thomas 'PointedEars' Lahn

Samuel said:
I need to retrieve the domain part of the url from the current page

How do I do that?

window.location.hostname or document.URL.match(/^[^:]+:(\/\/)?([^:]+)/)[2]


HTH

PointedEars
 
T

Thomas 'PointedEars' Lahn

pr said:
Evertjan. said:
Samuel Shulman wrote on 25 sep 2007 in comp.lang.javascript:
I need to retrieve the domain part of the url from the current page
var r = window.location.href.replace(/[^\/]*\/\/([^\/]*).*/,'$1')

not window.location.host ?

No. That would also yield the port part.


PointedEars
 
T

Thomas 'PointedEars' Lahn

T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 9/25/2007 4:51 PM:
Randy said:
Evertjan. said the following on 9/25/2007 1:58 PM:
Samuel Shulman wrote on 25 sep 2007 in comp.lang.javascript:
I need to retrieve the domain part of the url from the current page
var r = window.location.href.replace(/[^\/]*\/\/([^\/]*).*/,'$1')
var r = document.domain
That is the easiest standards-compliant approach, indeed. Well done.

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-2250147

And you doubted me enough to look it up. [...]

Write access to document.domain being used proprietarily
to work around the SOP made me suspicious enough for that:

http://www.mozilla.org/projects/security/components/same-origin.html


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Samuel said:
I need to retrieve the domain part of the url from the current page

How do I do that?

window.location.hostname or document.URL.match(/^[^:]+:(\/\/)?([^:]+)/)[2]

document.URL.match(/^[^:]+:(\/\/)?([^:\/]+)/)[2]

But I'd prefer document.domain instead.


PointedEars
 
T

The Magpie

Thomas said:
Thomas said:
Samuel said:
I need to retrieve the domain part of the url from the current page

How do I do that?
window.location.hostname or document.URL.match(/^[^:]+:(\/\/)?([^:]+)/)[2]

document.URL.match(/^[^:]+:(\/\/)?([^:\/]+)/)[2]

But I'd prefer document.domain instead.
I love that command, Pointed - thanks for mentioning it. It will save
lots of effort now that I know it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,404
Latest member
PerryRutt

Latest Threads

Top