When I use the following header
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
There is no error in my HTML file. But I am facing a problem. Every time I am loading this page , there is the need for internet connectivity.
I have developed an webpage through which some instruments would be controlled through node.js acting as a server. This would be accesible in the intranet (between local computers in LAN) only.
Is there any method to use jquery as a local resource, i.e. If i download and save these files and use it from the local hard disk.
I saved both the files jquery-1.8.3.js and jquery-ui.js in the same folder as the html and used it with <script src="/jquery-ui.js"></script> it is giving resource not found 404 error.
If the .js file is in the same folder as the .html, then you should be able to include it with
<script src="jquery-1.8.3.js"></script>
Download the jquery and put it in your scripts folder and use like this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="scripts/jquery-1.8.3.min.js"><\/script>')</script>
This will first check for the CDN if exist it will load from CDN other wise it will take local one
uses of CDN are in this link
Related
I have simple one page html/js/ReactJS app which is used with the help of such scripts added to index.html. It is running without any server, because client needs it to be used only on his computer:
<script crossorigin src="https://unpkg.com/react#16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom#16/umd/react-dom.production.min.js"</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.25.0/babel.min.js"></script>
How can I make this app working offline? I can use Node Server, but when application is downloaded by client it needs to be opened using the only index.html file.
Just download the three files above:
react : https://unpkg.com/react#16/umd/react.production.min.js
react-dom : https://unpkg.com/react-dom#16/umd/react-dom.production.min.js
babel : https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.25.0/babel.min.js
You can do this by going to the src links in your script tags above, right-click the webpage, click Save As, choose file type as JavaScript and then replace the above src links in your index.html to those downloaded files.
You can create a special folder for the site and within the folder, you can paste a copy of your index.html file as well as a js folder and keep the above three downloaded JavaScript files in that js folder.
You can now simply replace the src link in the above three scripts tags like this:
<script src="js/react.production.min.js" />
<script src="js/react-dom.production.min.js" />
<script src="js/babel.min.js" />
However, this only works if the client is just viewing the site. If the client wants to say, edit the files and want something like hot reload, they will need to set up a server for that.
I'm starting a chrome app. But things like this doesn't work for security reason.
<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
<script src='app.js'></script>
So how to add those 2 kind of script to my app?
I tried different things in the manifest file but none of them have been successfull
The simplest way to avoid security issues is to download jquery-1.11.0.min.js and place it in your script directory. This will ensure you won't have security SOAP issues. Then include the files like this:
<script src='/example_local_directory/jquery-1.11.0.min.js'></script>
<script src='/example_local_directory/app.js'></script>
Is it possible to have a JavaScript file with .css extension instead and still work inside the <script src="myJs.js"></script>?
Reason? webs.com won't accept .js files unless you're a Pro user. I've tried using Dropbox as host, but it becomes too slow.
Have you tried to force content type in the script tag ?
<script type="text/javascript" src="myJs.css"></script>
I am new to Jquery and AJAX. I am trying to upload the file using AJAX call. When I set the script reference as from website, its working fine, but when I download it and set reference as local folder, its not working. What is wrong with my code?
When I use :
<script src="http://malsup.github.com/jquery.form.js"></script>
its working fine,
but when I use
<script type="text/javascript" src="http://localhost:8080/Upload/js/jquery.js"></script>
or
<script type="text/javascript" src="js/jquery.js">
its not working......
Add jquery.form.js library in your website folder under js folder, and
Change
<script type="text/javascript" src="js/jquery.js">
To
<script type="text/javascript" src="js/jquery.form.js">
This version points to a file on that web site:
<script src="http://malsup.github.com/jquery.form.js"></script>
This version points to a file on your LOCAL server (machine) via port 8080 (usually NOT a great idea)
<script type="text/javascript" src="http://localhost:8080/Upload/js/jquery.js"></script>
This verison points to a js folder relative to the page it is linked on
<script type="text/javascript" src="js/jquery.js">
In order to use a file locally (like the last two), you will need to download that file, and save it to your web server (or local server) in a folder. In the second example, this would mean saving it to the Upload\js folder at the root of your local servers site (that machine).
In the third example, you would need to find the page it is linked in, create (if not present) a js folder under that folder and save the js file at that location.
Note that it is always a good idea to use the original name form or something similar rather than jQuery.js - as that is often confused with the jQuery library itself.
An examples might be save it as:
jquery.form.js
malsup.jquery.form.js
malsup.version1.jquery.form.js
or some such named instance.
NOTE One way of making this as generic as might be would be to use
<script type="text/javascript" src="/Upload/js/jquery.js"></script>
This points to a folder called Upload with a sub folder js (Upload\js)which is based at the root of your web site. For instance if your site is based at your windows e: drive in a wwwroot folder it might be:
E:\wwwroot\Upload\js\malsup.jquery.form.js
I run a sub-site at my work, and while my live site is on the same "main server" as the company's main site, my dev environment is hosted on a separate server.
For some reason my dev site is unable to access a specific JavaScript file that is hosted on the "main server". All of the other JavaScript files, like jQuery, and jQueryTools can be accessed, but main.js cannot. My only guess would be because it is a custom JavaScript file created by our head web developer, but I don't know why that would make a difference. (Cross-site scripting limitations?)
I link to it just like I do with all the other JavaScript files, right after our main wrapper (it's the 3rd from the bottom):
<script type="text/javascript" src="ui/2009/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="ui/2009/js/jquerytools/1.2.2/jquery.tools.min.js"></script>
<script type="text/javascript" src="ui/2009/js/jquery.cycle.all.min.js"></script>
<script type="text/javascript" src="ui/2009/js/main.js"></script>
<script type="text/javascript" src="ui/2009/js/jquery.jgfeed-min.js"></script>
<script type="text/javascript" src="ui/2009/js/hr.js"></script>
To troubleshoot follow these steps:
Check whether the file ui/2009/js/main.js is actually in that
location, if so be sure it doesn't have uppercase characters (the
server OS may be case sensitive)
Check whether the file main.js has the same permissions (i.e. chmod) as the other .js files (e.g. 755)
Check whether the file main.js is actually accessed (how do you know the file is
not accessed from your page in the dev server? It may be accessed but not working because of variable
conflicts with the .js you previously load, for instance). To do so,
you can a) check the server logs and see if you have a "not found"
error referred to the main.js file b) in main.js delete temporarily all
the content and print some simple output (either to screen with
document.write or to the javascript console with console.log)