javascript - How to properly initialize timezone-js - javascript

Im trying to learn the timezone-js I got from here.
I think I followed the instructions on how to get started. I downloaded all the necessary files including the Olson files but Im getting this error when I check my firefox console: Error: Error: Error retrieving "../files/tz/northamerica" zoneinfo files.
My code is (jtimezone.html):
<html>
<head>
<script type="text/javascript" src="../javascript/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../javascript/timezone-js/src/date.js"></script>
<script type="text/javascript">
$(document).ready(function () {
timezoneJS.timezone.zoneFileBasePath = "../files/tz";
timezoneJS.timezone.defaultZoneFile = "asia";
timezoneJS.timezone.init();
var dt = new timezoneJS.Date('10/31/2008', 'America/New_York');
alert(dt);
});
</script>
</head>
<body>
</body>
</html>
I think I have set the file path for the zoneFileBasePath. Anyway my html is located at /home/idiotboy/Documents/timzone_test/html. The downloaded timezone-js is at /home/idiotboy/Documents/timzone_test/javascript. The tz files are at /home/idiotboy/Documents/timzone_test/files.
Please help. If you can suggest a better/easier way to handle timezones in javascipt please do. Im still a beginner. Thanks.

Browsers don't allow AJAX to access local filesystem. You'll need to serve you page through Apache or Nginx and open your html with the URL localhost or 127.0.0.1

Related

How to load commonmark.js in a local HTML file?

I was following the steps and wrote a demo HTML. Here are the steps in the README of https://github.com/commonmark/commonmark.js#commonmarkjs :
For client-side use, you can do make dist to produce
a standalone JavaScript file js/dist/commonmark.js,
suitable for linking into a web page, or fetch the latest
from
https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js,
or bower install commonmark.
Here is my demo HTML.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js"></script>
<script>
window.onload = function() {
console.log(commonmark)
}
</script>
<body></body>
</html>
Here is a JSFiddle URL for my demo: https://jsfiddle.net/y3xohp7x/
I saved this HTML locally in a file named foo.html and opened this local file with Firefox 55.0.1.
But if I load it with Firefox 55.0.1, I get the following errors in the console.
Loading failed for the <script> with source “https://raw.githubusercontent.com/jgm/commonmark.js/master/dist/commonmark.js”. foo.html:5
ReferenceError: commonmark is not defined foo.html:9:5
Questions:
Why does this error occur?
How can I resolve this error without having to copy commonmark.js to the local filesystem?
Is it a bug in the commonmark.js README documentation that I quoted above or is it an error in my understanding of the documentation?
Edit
Actually, there apparently is a way to do this for github content in particular: https://rawgit.com/
This website gives you a link to a version of the script that will be served with the correct MIME-type.
So this should load the script properly for you:
<script type="application/javascript" src="https://cdn.rawgit.com/jgm/commonmark.js/master/dist/commonmark.js"></script>
https://jsfiddle.net/w1uvq59r/
Original Answer
The reason is that the script source is sent back with the headers:
"Content-Type": "text/plain"
"X-Content-Type-Options": "nosniff"
The latter header prevents the browser from executing the script due to the fact that the content-type is not executable, like "application/javascript". Which means unfortunately there is really no way to get the script to load remotely. Here is a thread with more information on a similar problem.
The only solution, as far as I can tell, is to load it locally, like so:
<script type="application/javascript" src="path/to/the/file.js"></script>

Cant find file on blueonyx server running apache

I got apache running on a blueonyx server. There is a piece of code in a php file which looks like this
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script type="text/javascript" src="/folder_name1/folder_name2/file_name.nocache.js"></script>
.....
If I load up that page and check the network tab in my browser it loads that file_name.nocache.js fine, I can even go to http://192.168.0.123/folder_name1/folder_name2/file_name.nocache.js and the browser will display the contents of that file.
But if I ssh onto that server, I can't find that file. Not even that folder or any of those folders.
I have checked phpinfo() and it is not auto_prepend_file anything other than a file that just contains putenv("_HTTP_HOST=".#$_SERVER["HTTP_HOST"]);.
I have tried find / -name "folder_name1" with root, no luck either.
I have tried grep on the contents in file_name.nocache.js, no luck either.
I don't understand how is this possible. Can someone shed a light on me please?
To whoever run into similar problem, i found out what happened.
It was these 2 lines here that are pulling the invisible file out of no where:
./etc/httpd/conf/httpd.conf:ProxyPassReverse /folder_name1 http://192.168.0.111/folder_name1
./etc/httpd/conf/httpd.conf:ProxyPass /folder_name1 http://192.168.0.111/folder_name1

in Safari, jquery not found when query.min.js is called

I have a simple HTML page which calls jquery.min.js
The JavaScript (which includes jQuery functions) on the page runs fine.
However, if I look at Safari's Web Inspector Console, the following error is reported:
http://www.mydomain.com/js/jquery-1.10.2.js
Failed to load resource: the server responded with a status of 404 (Not Found)
If I create an un-minified version of jQuery and save it as jquery-1.10.2.js, then the error message goes away.
Does jquery.min.js require the un-minified version of jQuery to reside in the same folder?
Update
Here is the HTML in its entirety. As you can see it is very simple:
<!DOCTYPE html>
<html>
<head>
<title>My Homepage</title>
<script src="/js/jquery.min.js"></script>
<script>
$ (document).ready(function() {
$('body').css('background-color', '#f00');
});
</script>
</head>
<body>hello world</body>
</html>
You are trying to load
http://www.mydomain.com/js/jquery-1.10.2.js
somewhere in your project. Search for jquery-1.10.2.js in your root folder and modify all the occurrences to valid paths.
This seems to be a "feature" of Safari but I could not find any reference to it in the documentation. If it cannot find the unminified version of .js file, it will beautify to make it easier to debug. It is similar how Chrome checks for the .map file of a minified JavaScript file but Safari goes further and tries to load the same file without the ".min" part.
Apparently there is no way to disable this feature, at least we could not find one.

Trying to fetch json string from internet api

I am trying to fetch the json string from this url:
http://status.mojang.com/check
however every time i get a failure or this:
XMLHttpRequest cannot load http://status.mojang.com/check. Origin null is not allowed by Access-Control-Allow-Origin.
Any help appreciated
<!DOCTYPE html> <html> <head> <title>mc stats</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script> <meta http-equiv="Access-Control-Allow-Origin" content="*"> </head> <body>
<div id="minecraft"> </div>
<script> (function() { var flickerAPI = "http://status.mojang.com/check?jsoncallback=?"; $.getJSON(flickerAPI)
.done(function( data ) {
console.log(data); }); })(); </script> </body> </html>
You need to run the webpage in a server and this problem should go away. There might be a way to do it with Google Chrome, but I am not aware of it. When I have this issue, I typically run my file with Aptana Studio. It is a free download and it causes the file to be served up from a server instead of just being read from your file system. It defaults to Firefox, but you can just paste the url in Chrome and everything should work like you expect, unless there are other errors.
If you are running a mac/linux you also have access to the python simple server and it should serve it up also. Run the command python -m SimpleHTTPServer from the file directory and you should be able to see it at localhost:8000. Good Luck!

How include custom javascript library to google site?

Please, help include custom javascript library "jquery-EmbedPicasaGallery.js" to google site.
I tried 3 methods and always have error:
failed to load external url jquery-EmbedPicasaGallery.js
I tried:
.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="https://googledrive.com/host/0BziEumkvYpL6Ql9NRFhET2FXM1E/jquery-EmbedPicasaGallery.js"></script>
.
<script type="text/javascript" src="https://docs.google.com/uc?id=0BziEumkvYpL6ZmlHZ2FWQ1NrVG8"></script>
.
<script type="text/javascript" src="https://docs.google.com/uc?id=0BziEumkvYpL6ZmlHZ2FWQ1NrVG8&export=download"></script>
Have you tried downloading the script and running it from your own server?
Is your site being tested on a server, or locally?
It is common for errors to occur when attempting certain things locally, so make sure to run on a server, especially in cases involving php, ajax, canvas image data, http headers, and cookies, to name a few.

Categories

Resources