I have the following code. It works in an html document. I would like to move the script in the head to an external .js document. Still very new at this and so far everything I’ve seen has to do with functions, but I want to assign the variables in the .js doc so they’re not viewable in the html. Any help would be appreciated. Thanks!
<html>
<head>
<script type="text/javascript">
var userName = "exampleaddress";
var emServer = "exampledomain.com";
var tagLine = "?subject=Questions/Comments Re: exampledomain.com";
var emLink = userName + "@" + emServer + tagLine;
</script>
</head>
<body>
<script>
document.write("<a href='http://www."+emServer+"'>");
document.write(emServer);
document.write("<a>");
</script>
<br>
<script>
document.write("<a href='mailto:"+emLink+"'>");
document.write(userName);
document.write("<a>");
</script>
</body>
</html>
To achieve what you have asked:
file.jscontains:EDIT:
The part of your question that isn’t possible is having the variables not visible.
HTMLansJSfiles are always accessible in plain text (for lack of better words)If you are trying to hide these values from the end user, it is impossible in the way you have asked. Tell us your true purpose and we might be able to propose a better solution.