Solved

Determining URL of current page

Posted on 2004-10-14
6
211 Views
Last Modified: 2009-12-16
How can I use JavaScript to determine the URL of the current HTML page (the page in which the script is running)?
0
Comment
Question by:vladc6
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:Kupi
ID: 12310839
Try:

var url = window.location;

:)
0
 
LVL 3

Accepted Solution

by:
Kupi earned 250 total points
ID: 12310863
If you need a function:

<script type="text/javascript">

function getPageLocation() {
  return window.location;
}

</script>

<body onload="var url = getPageLocation(); alert(url);">
0
 
LVL 25

Expert Comment

by:devic
ID: 12312580
location is an object
and string is location.href
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 3

Expert Comment

by:Kupi
ID: 12312675
location Property
This property contains details of the current URL of the window and its value is always the Location object for that window.

Syntax: window.location

http://www.devguru.com/Technologies/ecmascript/quickref/window.html
0
 
LVL 25

Expert Comment

by:devic
ID: 12312733
yes, and if we need the string, then is location.href
0
 

Author Comment

by:vladc6
ID: 12314307
Thanks everyone... window.location.href worked!
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

Suggested Solutions

Title # Comments Views Activity
Debugging step-by-step Jquery/Javascript 6 57
Allow space in this pattern 2 48
Replace &lt; with < 14 56
how to handle long text strings in javascript or ajax 1 2
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

911 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

17 Experts available now in Live!

Get 1:1 Help Now