Capturin URL in JavaScript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Capturin URL in JavaScript

Post by mzfp2 »

Hi

is it possible to read the current URL in the address bar when a page loads using JavaScript?

Thanks

http://www.alljammin.com -Free funky dating and flirting
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Ummm pretty sure yo can with somthing like:

self.location

or maybe

window.location

I know ive used it before, but cant quite remember.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Solution

Post by anjanesh »

Code: Select all

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function GetURL(srcID)
 &#123;
 alert(document.location.href); 
 &#125;
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="Button" id=button1 onclick="GetURL(this)">
</BODY>
</HTML>
jaxn
Forum Commoner
Posts: 55
Joined: Fri Jan 16, 2004 1:50 pm
Location: Nashville, TN

Post by jaxn »

You posed this same question a couple of days ago.
viewtopic.php?t=16799

Why use JavaScript? Why not use this:
$requested_url = $_SERVER['REQUEST_URI'];

Are you trying to get the parent of a frame?

-Jackson
mzfp2
Forum Contributor
Posts: 137
Joined: Mon Nov 11, 2002 9:44 am
Location: UK
Contact:

Post by mzfp2 »

Well im trying to implement faceparty functionality so if someone types say http://www.alljammin.com/shizzle it should diaplay shizzle's profile.

However the only way I can implement is to put a script in my custom 404 error pages which traps the page nout found error, and captures the URL, and reads the username from it, then does a redirect
Post Reply