Jump to content

[SOLVED] outputting variables from an included file??


Dragen

Recommended Posts

Hi,

I was just wondering about calling javascript variables. I'm not brilliant at javascript and I'm not sure what I'm trying to do can be done but here it is..

 

I have a javascript file which sets some variables:

var width = screen.width;	
var height = screen.height;
var ref = ""+document.referrer;
var color = screen.colorDepth;

I then have my html file which includes the javascript file:

<body>
<script type="text/javascript" src="javascript.js"></script>
</body>

Now what I'd like to do is write some javascript inside the script tags, which uses the variables set within the file.. for examplew:

<body>
<script type="text/javascript" src="http://localhost/counter/javascript.js">
document.write('ref: '+ref+'<br />colour: '+color+'<br />width: '+width+'<br />height: '+height);
</script>
</body>

Please don't suggest just doing the document.write inside the javascript file itself.. I do have a reason for wanting it done like this ;)

 

Anyway.. anyone know of a possible way of doing this? I tried the code above and got nothing.

 

Thanks

Link to comment
Share on other sites

<body>
<script type="text/javascript" src="http://localhost/counter/javascript.js"></script>
<script type="text/javascript">
document.write('ref: '+ref+'<br />colour: '+color+'<br />width: '+width+'<br />height: '+height);
</script>

 

--2 script tags, one with a src, one without.  Both will be considered at the same level by the javascript parser.

Link to comment
Share on other sites

thanks.. I hadn't thought of that ::)

I was also hoping just to do it in one tag though, to make it easier for people to use as it's a bit of code for clients to copy and paste into their pages.

 

Thanks for the ever so simple answer!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.