Dragen Posted October 6, 2007 Share Posted October 6, 2007 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 https://forums.phpfreaks.com/topic/72126-solved-outputting-variables-from-an-included-file/ Share on other sites More sharing options...
mainewoods Posted October 6, 2007 Share Posted October 6, 2007 <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 https://forums.phpfreaks.com/topic/72126-solved-outputting-variables-from-an-included-file/#findComment-363613 Share on other sites More sharing options...
Dragen Posted October 6, 2007 Author Share Posted October 6, 2007 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 https://forums.phpfreaks.com/topic/72126-solved-outputting-variables-from-an-included-file/#findComment-363627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.