0

I know it is possible to put JavaScript is a specific .js file and then include this in any page by just doing...

<script src="MyJavaScript.js"></script>

I note that with respect to these .js files that are included:

  1. They do not actually have to end with .js
  2. Their content should not be enclosed with tags

However, I need to import some JavaScript that is in a file ending with extension .page (I am using force.com platform) where th JavaScript is enclosed with the tags. The reason I need to do this is so I can write som unit tests using quint. Now, my hands are tied here. The cleanest way is to obviously refactor out the JavaScript from .page file into a .js file but I can't do this. I want to know is there any way I can just import the script snippets enclosed with tags.

Many thanks

dublintech
  • 16,815
  • 29
  • 84
  • 115
  • Why does the standalone JS file have ` – Barmar Oct 08 '12 at 15:55
  • IT is a separate .page file with embedded javascript. The analogy would be a separate JSP file which embedded – dublintech Oct 08 '12 at 16:03

3 Answers3

1

Is this what you are looking for?

<script type="text/javascript" src="MyJavaScript.page">

John Resig has a good approach to deprecate Tags. Might be worth a look.

There is also a SO thread on this Tag issue. Please see here.

Community
  • 1
  • 1
Totero
  • 2,524
  • 20
  • 34
1

As @totero said, you can specify the script type with the attribute

<script type="text/javascript" src="myFile.annoyingExtension">

But please, don't forget to close the tag otherwhise you will get strage bugs:

<script type="text/javascript" src="myFile.annoyingExtension"></script>

Close the tag itself wont work so please, don't do this

<script type="text/javascript" src="myFile.annoyingExtension" />
A. Matías Quezada
  • 1,886
  • 17
  • 34
0

You mention including Javascript, and by the looks of it, you're including them in a HTML document. Do you have any other programming or scripting language available to you that allows you to edit the document? If you can use something like PHP or ASP within the platform, you could have it read the .page file and echo it into your HTML output document (possibly stripping the <script> tags from it at your convenience).

Joost
  • 4,094
  • 3
  • 27
  • 58
  • This is the force.com platform. So options seriously limited. – dublintech Oct 08 '12 at 15:30
  • If you're limited to only using Javascript, you could consider pulling the .page file in via AJAX, removing the script-tags and then executing it dynamically with the eval() function. Use with caution, though. – Joost Oct 08 '12 at 15:33