Click to See Complete Forum and Search --> : Help needed with 'window.location.href'


cdhanjal
02-10-2003, 09:30 AM
Hi Everybody,
I am trying to create a webpage which will automatically pick the url , the domian name and create an email address. For example:
If i put my page on www.mimi.ch
it will say 'Welcome to Mimi'
display 'http://www.mimi.ch'
and create an email address as 'info@mimi.ch'.

I was told that i could use 'window.location.href' and found a script which lets me display 'http://www.mimi.ch' .

<script type="text/javascript">
var myloc = window.location.href;
var locarray = myloc.split("/");
delete locarray[(locarray.length-1)];
var arraytext = locarray.join("/");
document . write ('"<tt>' + arraytext + '</tt>."');
</script>

Now being new to Java, how do I do the other two.
Can anybody help me.

Thanking in advance,

C Dhanjal

LAwebTek
02-10-2003, 10:49 AM
Try using the following. If you want it to display the welcome in an alert box, simply change the first occurance of document.write to alert

<script type="text/javascript" language="JavaScript">
var myloc = window.location.href;
var locarray = myloc.split("/");
delete locarray[(locarray.length-1)];
var arraytext = locarray.join("/");
var namarray = myloc.split(".");
var mail = "info@" + namarray[1] + ".com";
document.write("Welcome to " + namarray[1] + "<br>");
document.write(arraytext + "<br>");
document.write("<a href='mailto:" + mail + "'>" + mail + "</a>");
</script>

Regards,
S.Bishop
LAwebTek.com

LAwebTek
02-10-2003, 11:07 AM
I just noticed that you are not on a .com domain so here's the fix:

<script type="text/javascript" language="JavaScript">
var myloc = window.location.href;
var locarray = myloc.split("/");
delete locarray[(locarray.length-1)];
var arraytext = locarray.join("/");
var namarray = myloc.split(".");
var sufarray = namarray[2].split("/");
var mail = "info@" + namarray[1] + "." + sufarray[0];
document.write("Welcome to " + namarray[1] + "<br>");
document.write(arraytext + "<br>");
document.write("<a href='mailto:" + mail + "'>" + mail + "</a>");
</script>