PDA

View Full Version : Show relative URL?


d11wtq
02-11-2005, 10:50 AM
Hi,

See this example code....

<div style="width:150px; height:90px; border:1px solid black; cursor:pointer" onClick="window.location='?mode=newmode'">
<a href="?mode=newmode">Switch to a new mode</a>
</div>


If this was in http://mysite/myfile.php then the user could click the loink to go to http://mysite/myfile.php?mode=newmode OR he/she could click the div itself to get the same result.

Only problem is that the window status bar will not show the URL the DIV is pointing to. Is there some quicky way of making it do this which is portable across domains? I am aware that window.status='http://mysite/myfile.php?mode=newmode' does it but that would not work if I moved the http://anothersite - see what I*'m trying to do?

Thanks very much :)

brothercake
02-11-2005, 12:29 PM
see what I*'m trying to do?
er, no - what are you trying to do?

waolly
02-11-2005, 01:11 PM
This isn't a javascript solution but I see you calling a php file there.

In PHP you can use $HTTP_HOST and $SCRIPT_NAME to construct where you currenltly are - you can then place the results from these variables in the generated HTML.

The following PHP code gives you current full location.


<?=$HTTP_HOST.$SCRIPT_NAME?>

Bolter99
02-12-2005, 06:06 AM
<div style="width:150px; height:90px; border:1px solid black; cursor:pointer" onClick="window.location='myfile.php?mode=newmode'">
<a href="myfile.php?mode=newmode">Switch to a new mode</a>
</div>

just put the php file name in the urls... other wise it will think the modes are the file names...[/