You can place the script in the head or body as you like. The script will behave as if it was/were located exactly where you put the script tag in the document.
The version with the modal preterite "was" is grammatical, and is acceptable.
As to the version with the irrealis "were": Since the matrix clause has present tense, that irrealis "were" version is also grammatical. It has the same interpretation as the version using the modal preterite "was".
There is a related section in the 2002 reference grammar by Huddleston and Pullum et al., The Cambridge Grammar of the English Language (CGEL), within their section "As if and as though", pages 1152-3. It has interesting info that answers the OP's question and some related questions, such as those about:
- open vs remote conditionals,
- irrealis "were" versus preterite (past-tense),
- irrealis "were" versus past-perfect,
- hypercorrection with irrealis "were".
The CGEL excerpt:
Irrealis were and the preterite
The as if/though construction is one of those that allow irrealis were or a modal preterite. Where the matrix clause has present tense, we have the expected contrast in the content clause between were or modal preterite (e.g. "was" -- F.E.) and present tense:
 He moves about on camera, angular, emaciated, graceful, as if his body were/is weightless.
The version with irrealis were is motivated by the fact that his body is not actually weightless, i.e. by the counterfactuality of the content clause. The version with is, by contrast, presents his body's being weightless as an open possibility, thereby suggesting that he gives the appearance of being weightless.
Compare also She acts as if she hated me and She acts as if she hates me (=[40.iii]). The latter conveys that the way she acts suggests that she does hate me and may well do so, whereas the modal preterite hated presents her hating me as a more remote possibility (though it is certainly not presented as counterfactual).
Less straightforward is the case where the matrix clause is in the preterite:
- i. He was treated as if he were a Commonwealth citizen.
- ii. As the trooper left the room, the gambler turned to the army girl with an odd expression, as though he were remembering painful things.
The natural interpretation of [i] is that he was treated like a Common citizen although he wasn't one. Example [ii], however, doesn't imply that he wasn't remembering painful things: on the contrary, it suggests that he was or appeared to be.
In [i] we could have as if he had been a Commonwealth citizen, with the perfect marking backshift (or past time) and the preterite marking modal remoteness; it is, however, much more usual in such contexts to have an irrealis or simple preterite after as if/though than a preterite perfect.
The irrealis in [43.ii] does not appear to be semantically motivated: certainly if we had a simple preterite in this context we would have no reason to regard it as a modal preterite. This were is therefore probably best regarded as belonging with the 'extended' uses of the irrealis discussed in Ch. 3, &1.7. Like them, it has the flavour of a hypercorrection: was is a less formal variant of were in modal remoteness constructions like [i], so that some speakers feel were to be stylistically preferable to was in similar constructions where was was not traditionally stigmatized. [fn 3]
footnote 3: This extended use of irrealis were is occasionally found in constructions where the matrix has present tense: It sounds from the guide book as if Verona were worth a visit. The flavor of hypercorrectness is stronger here: the example falls under the use of as if seen in [40.iv], which indicates that the content clause is relatively likely to be true, making the irrealis semantically inappropriate.