Solved

Two basic javascript questions - amend font and get ip/hostname

Posted on 2004-10-01
14
526 Views
Last Modified: 2013-12-03

Is there a way of obtaining the ipaddress and hostname of my machine using javascript and insert it into a redirect?, like this :
<script language="Javascript">
alert ("Selected Contracts Have Been Completed")
window.location="http://<my ip address>:8080/somepage.jsp";
</script>

Also how can I change the font and size of the text displayed in the alert?

Im using windows XP

Thank you
0
Comment
Question by:CtrlCtrlV
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 12

Expert Comment

by:monosodiumg
ID: 12198768
DO you mean the ip of the client? Hostname doesn't make sense for the client.
0
 

Expert Comment

by:michaelfriesy
ID: 12198832

No the ip of the hose machine , ie the machine the javascript code is on.
0
 

Expert Comment

by:michaelfriesy
ID: 12198834
>>hose,
I mean host
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 12198862
The host the page is served from?

You can get that from the Location object:
window.Location.hostname
0
 

Expert Comment

by:VolSpeak
ID: 12198878
This would work?

window.location="http://window.Location.hostname:8080/somepage.jsp";
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 12198909
No it won't. It would be:

window.location="http://" + window.Location.hostname + ":8080/somepage.jsp";

0
 

Expert Comment

by:VolSpeak
ID: 12198920
Ok, ill try that

>>Also how can I change the font and size of the text displayed in the alert?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:monosodiumg
ID: 12198975
You can't. The alert is provided by the OS and you can't control anything except the text.
If you ned something prettier, you can make up your own using window.open to open anew window then document.write to write HTML into it.
0
 

Expert Comment

by:VolSpeak
ID: 12198992

>>window.location="http://" + window.Location.hostname + ":8080/somepage.jsp";

That doesnt work for me, it just brings me to this url:
http://undefined.cc/
0
 

Expert Comment

by:VolSpeak
ID: 12199001
>>If you ned something prettier, you can make up your own using window.open to open anew window then document.write to write HTML into it.

Any simple examples?
0
 
LVL 12

Expert Comment

by:monosodiumg
ID: 12199195
You could grab one that suits your needs from http://www.pacosdrivers.com/wm/js.asp?cat=1.
This one looks suitable: http://www.dynamicdrive.com/dynamicindex11/abox.htm

A simple example can be found in this discussion:
http://www.webxpertz.net/forums/archive/index.php/t-9699.html

0
 

Expert Comment

by:marshmeli
ID: 12201137
>>That doesnt work for me, it just brings me to this url:
>>http://undefined.cc/

hmm, that should work try just "location.hostname"

in the browser window you can test the statement by typing:

javascript:[statement];

and try

javascript:[window.location.hostname];
and
javascript:[location.hostname];

they should both give the same result, and print the host address...
0
 
LVL 12

Accepted Solution

by:
monosodiumg earned 200 total points
ID: 12205182
Location -> location
My typo. sorry.
0
 

Author Comment

by:CtrlCtrlV
ID: 12809717
thats fine, thank a mil and sorry about taking so long to get back :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now