MozillaZine

How to pass variables in a URL?

User Help for Mozilla Firefox
(Anonymous/guest posting allowed)
jmborr
 
Posts: 2
Joined: April 6th, 2006, 8:55 am
April 6th, 2006, 9:11 am

Post Posted April 6th, 2006, 9:11 am

I don't know if this is possible, but I'd like to write a URL as
<a href="file://$MYDIR/somefile.txt">one file</a>
and then somehow :-k firefox should resolve variable $MYDIR.
The idea is to use the same address for Linux and Windows, where $MYDIR means different paths.
Any help, please?
jose

LitenGalenBil
 
Posts: 8
Joined: April 6th, 2006, 8:51 am
April 6th, 2006, 9:18 am

Post Posted April 6th, 2006, 9:18 am

Yes, you can do it with Javascript.

jmborr
 
Posts: 2
Joined: April 6th, 2006, 8:55 am
April 6th, 2006, 1:08 pm

Post Posted April 6th, 2006, 1:08 pm

I have no clue hot to use Javascript. Is there some code snippet I can look at?
jose

logan

User avatar
 
Posts: 3452
Joined: May 22nd, 2003, 3:51 pm
Location: NGC 2403
April 6th, 2006, 3:11 pm

Post Posted April 6th, 2006, 3:11 pm

Code: Select all
<script>
var MYDIR = '/home/user';
document.write('<a href="file://' + MYDIR + '/somefile.txt">one file</a>');
</script>

I don't think you can get an environment variable with regular old javascript, but there is a mozilla component you can use:
Code: Select all
var env = Components.classes["@mozilla.org/process/environment;1"]
                    .getService(Components.interfaces.nsIEnvironment);
alert(env.get('MYDIR'));

texmex
 
Posts: 403
Joined: March 26th, 2006, 8:58 am
Location: NE Lincs
April 6th, 2006, 4:06 pm

Post Posted April 6th, 2006, 4:06 pm

Now if I understand correctly, you want to select a separate document, dependant on the users OS. The thing you want to look at is the navigator.platform

for instance, your unix style page would have something like:
Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>Whatever</title>
   <script type="text/javascript">
function platformCheck()
  {
  var v=navigator.platform.substring(0,3).toUpperCase(); 
  if (v=="WIN")
    location.href="windowsVer.htm";
  }

</script>
  </head>
  <body onload="platformCheck()">
blah blah blah..
  </body>
</html>


and slightly different, in your Windows style document you could include.

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>Whatever</title>
   <script type="text/javascript">
function platformCheck()
  {
  var v=navigator.platform.substring(0,3).toUpperCase(); 
  if (v!="WIN")
    location.href="unixVer.htm";
  }

</script>
  </head>
  <body onload="platformCheck()">
  </body>
</html>


This would ensure that, in the event the user ends up at the wrong page, their browser will automatically switch over to the appropriate.

You could also modify this slightly to "calculate" the name of the new page based on the current location.

for example, if your Window document page names were identical to the unix version (but with the addition of a preceding W).

In your unix pages you could use the expression
"W"+location.href to find the windows page.

In the meantime, in your windows pages you could use the expression
location.href.substring(1) to get to the unix version.

this would save you having to edit page name within the document on every page.

Post a reply

Quote Selected

Enter the code exactly as it appears. All letters are case insensitive, there is no zero.
 

Return to Firefox Support


Who is online

Users browsing this forum: DanRaisch and 16 guests