2 snips. JS & PHP version. URL Parsers {updated old thre
Posted: Mon Mar 21, 2005 10:49 am
I made this handy function because I regularly include onClick events in my page to act like hyperlinks. Unfortunately doing this doesn't show the URL in the status bar like a normal hyperlink would do. This function takes either a relative or absolute URL and builds the full URL from it then writes it to the status bar mimicking what <a href=....> would do. This looks very convincing if use along with style="cursor:pointer". Stick it in between your HEAD tags. It supports all protocols....
Example use:
Code: Select all
<script language="e;javascript"e; type="e;text/javascript"e;>
<!-- Hide from older browsers
//*************************************************
// Function: URL Constructor, showURL()
// Author: d11wtq (Chris Corbyn)
// Date: March 2005
// Usage: showURL('./somedir?mode=x')
//*************************************************
function showURL(loc) {
statusURL = ''
curLoc = unescape(window.location)
if (!/^\w+:\/\//.test(loc)) { //Has protocol in string
if (/^\//.test(loc)) { // Starts with /
curLocArray = curLoc.match(/^(\w+:\/\/ї^\/]+)/) //Up to first / after http://
statusURL = curLocArrayї1]+loc
} else if (/^\?/.test(loc)) {
curLocArray = curLoc.match(/^(\w+:\/\/ї^\?]+)/) //Is argument
statusURL = curLocArrayї1]+loc
} else if (/^\#/.test(loc)) {
curLocArray = curLoc.match(/^(\w+:\/\/ї^\#]+)/) //Is anchor name
statusURL = curLocArrayї1]+loc
} else if (locArray = loc.match(/^(\.\/)?(.+)?$/)) { //Strip the ./ if exists
subLoc = locArrayї2]
curLocArray = curLoc.match(/^(\w+:\/\/.+)\//) //Up to final /
statusURL = curLocArrayї1]+'/'+subLoc
}
} else {
statusURL = loc //Full URL (Absolute)
}
window.status = statusURL
return true
}
// End -->
</script>Code: Select all
<table border="e;1"e; style="e;cursor:pointer"e;>
<tr>
<td bgcolor="e;#FAFAFA"e; onClick="e;window.location='?mode=x'"e; onMouseover="e;showURL('?mode=x')"e; onMouseout="e;window.status=''"e;>Click me</td>
</tr>
<tr>
<td bgcolor="e;#AAAAFF"e; onClick="e;window.location='/subdir/myfile.php?page=7'"e; onMouseover="e;showURL('/subdir/myfile.php?page=7')"e; onMouseout="e;window.status=''"e;>Link here</td>
</tr>
</table>