File won't save as JavaScript extension in Notepad++ - javascript

I am trying to use an external JavaScript file in my HTML as follows:
<script src='MyScript.js'></script>
The issue is, I am getting the following error in the Web console:
Loading failed for the <script> with source "file:///F:/GIS%20Assessment%202/MyScript.js".
I have realised that MyScript is not saved as having the JavaScript extension, in my documents it says it's a "File" rather than a JavaScript file. I have tried changing the language to JavaScript and saving as a JavaScript file as soon as I save it in my folder it just converts to a generic file!
What do I do? How do I fix this and save my scripts as JavaScript?

This isn't really a programming question, and is likely to be closed, but to force it to have the extension, simply enclose the filename (with the extension) in quotes.
"MyScript.js"

I know this post is over a year old, but I found it worked when I typed the file extension in capitals when saving the file: "myfile.JS" instead of "myfile.js"

Related

How to correctly include a javascript file into html

I am trying to run a script through HTML but I am having some problems. I searched online and found how to do so, however the issue is that even if I correctly type the path of the .js file, it seems to add some strange characters before it.
This is in index.html
<script type="text/javascript" src="fractalTest/fractalTest.js"></script>
I expected this to work but when I open index.html in google chrome and inspect then look under the elements tab, this "â©fractalTest/fractalTest.js" is replacing "fractalTest/fractalTest.js" in the path of the file. I believe this is whats causing the error but I do not know how to fix it!
...it seems to add some strange characters before it.
That usually means that the file is saved with a byte-order mark (BOM) of some kind, but isn't being sent with the correct charset for that byte-order mark.
Be sure that the server is configured to serve the files with a specific encoding (UTF-8 is a good choice), and that you save the files using that encoding (in your text editor, etc.). It's also usually best not to include a BOM on UTF-8 files (although it's valid, some tools don't handle it well).
Side note: No need for the type attribute. The default is JavaScript.

Getting the file extension without knowing it's name

I need to know if there is a way to retrieve the real file extension without parse the filename.
In my code I split the file using the function split(filename, ".") then i get the last element of the array that the function returns.
Now, if I create a .pdf file called, for example test_file.pdf, the previous method works perfectly, but if i rename my file to test_file(without extension) I cannot retrieve the extension even if I know that the file is a PDF.
For example, if i rename test_file.pdf to text_file.jpg how can I recognize that the file is still a pdf and not an image file with .jpg extension?
I would like to know if there is a way to obtain this information, maybe using file metadata or other information related to the file.
I'm looking for a Javascript solution because I have to check the extension when I upload the file using a form (client side) but even a Java solution could be fine, can you help me?
Thank you in advance!
Look at this post and the marked answer: Get real file extension -Java code
I guess it's just what you need.

Using Notepad++

I'm using Notepad++ to do Javascript, and it doesn't work. This is what comes out in the web page:
, not the actual thing it would display when it runs properly.
I have the notepad++ 6.6.7 version.
Here's how I did it:
Write the code.
Change the language to Javascript.
Run it in Google Chrome.
And this is my result!?!?:
Am I not using Notepad++ correctly or my code has an error in it? Thank you so much!
Rename your file to somefilename.html.
You're saving your file as thing.txt. Save it as thing.html.
Also you're saying that you are working on javascript, but your code only contains html, so even you try to choose the language as javascript, javascript format won't work (but first save it as html file).
Browsers will render HTML and execute JavaScript in HTML documents not text documents as your filename of thing.txt suggests.
If you're experimenting try one of these sites: http://jsbin.com/ or http://jsfiddle.net/

Extract javascript from JSP to JS file

I'm trying to refactor parts of our front-end at the moment, using Intellij. We have a lot of javascript that is within our JSPs. I'd like to be able to extract from the JSP into a .js fil and replace it with a script tag referencing that file. I know how to extract to an 'includes' file, but I'd like a way of extracting and replacing the code with a proper script tag.
Does anyone know of a plugin that can accomplish this quickly and easily? (Or a pre-existing function in Intellij that I'm unaware of)
Please vote for this issue (it's 5 years old and had zero votes).
just create one file with .js extension copy and paste your js codes with their function names. then include that file in your jsp project header section.
eg:
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
thats all..

Retrieving a csv file from web page

I would like to save a csv file from a web page. However, the link on the page
does not lead directly to the file, but it calls some kind of javascript, which leads
to the opening of the file. In other words, there is no explicit url address for the
file i want to download or at least I don't know what it should be.
I found a way to download a file by activating Internet Explorer,going to the web page
and pressing the link button and then saving the file through the dialog box.
This is pretty ugly, and I am wondering if there is a more elegant (and fast) method to retrieve a file without using internet explorer(e.g. by using urllib.retrieve method)
The javascript is of the following form (see the comment, it does not let publish the source code...):
"CSV"
Any ideas?
Sasha
You can look at what the javascript function is doing, and it should tell you exactly where it's downloading from.
I had exactly this sort of problem a year or two back; I ended up installing the rhino javascript engine; grepping the javascript out of the target document and evaluating the url within rhino, and then fetching the result.

Categories