js for detecting domain

J

JavaDay

hi folks,

i'm a web designer who's just learning JS - wanted to know if there was a
function that could suss out which domain the page is residing on, and
assign a different variable string thus-wise.

my client has a simple one page site on 3 different domains, where the buy
now paypal button is directed to feed to 3 different shopping carts. it
would save me setting up 3 different local site def's if I could use one
site page that differentiated it's resident domain and inserted the shopping
cart link as a variable string, according to which domain it resided on. i
know php has a function to get IP address, not sure about JS.

thanks for any advice ...

Jed
 
S

Stevo

JavaDay said:
hi folks,

i'm a web designer who's just learning JS - wanted to know if there was a
function that could suss out which domain the page is residing on, and
assign a different variable string thus-wise.

my client has a simple one page site on 3 different domains, where the buy
now paypal button is directed to feed to 3 different shopping carts. it
would save me setting up 3 different local site def's if I could use one
site page that differentiated it's resident domain and inserted the shopping
cart link as a variable string, according to which domain it resided on. i
know php has a function to get IP address, not sure about JS.

thanks for any advice ...

Jed

I would think document.domain is what you're looking for.

To see it in action, go to a site in your browser, put this in the
address bar and hit enter:

javascript:alert(document.domain)
 
D

Doc O'Leary

JavaDay said:
i'm a web designer who's just learning JS - wanted to know if there was a
function that could suss out which domain the page is residing on, and
assign a different variable string thus-wise.

Use the document location.
thanks for any advice ...

When designing a simple web site, especially where the intent is get
money from the user, assume JavaScript is turned off.
 
J

JavaDay

JavaDay said:
hi folks,

i'm a web designer who's just learning JS - wanted to know if there was a
function that could suss out which domain the page is residing on, and
assign a different variable string thus-wise.

my client has a simple one page site on 3 different domains, where the buy
now paypal button is directed to feed to 3 different shopping carts. it
would save me setting up 3 different local site def's if I could use one
site page that differentiated it's resident domain and inserted the
shopping cart link as a variable string, according to which domain it
resided on. i know php has a function to get IP address, not sure about
JS.

thanks for any advice ...

Jed

a little more on the "detecting domain issue"

the "document.domain" property worked quite well, in assigning the shopping
cart URL.

one other issue that's come up for me, along the same lines ...
I use an implanted javascript "statcounter" for my sites,
and want to use the same "document.domain" property to select
which JS "implant" I'm going to use.

the Statcounter code contains two script statements, with line breaks etc
as indicated below.

My plan is to issue a "document.write" statement to "write out"
one of the 3 statcounter scripts, according to which domain is returned via
the
"document.domain" property. So, I'd actually be using "document.write"
command
to "print" out these two javascripts into my html document.

my question is, how do I include line breaks in the document.write
statements, so they will end up printed on multiple lines as below?

if I enclose the document.write statement in single quotes (as opposed to
the double-quotes used in the js scripts below), it should work fine, but
I'm not sure of the scripting for line breaks.

thanks for any help...

=========BEGIN SAMPLE STATCOUNTER CODE==================

<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=4648499;
var sc_invisible=1;
var sc_partition=56;
var sc_click_stat=1;
var sc_security="5b934116";
</script>

<script type="text/javascript"
src="http://www.statcounter.com/counter/counter.js"></script><noscript><div
class="statcounter"><a title="joomla stats"
href="http://www.statcounter.com/joomla/"
target="_blank"><img class="statcounter"
src="http://c.statcounter.com/4648499/0/5b934199/1/"
alt="joomla stats" ></a></div></noscript>
<!-- End of StatCounter Code -->

================END CODE=======================
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top