I don't know how should I titled this question but hope my friends will understand the problem and will help me :)
I want to show log message in arabic language using JavaScript alert() function, for which I code:
alert('أدخل سعر الافتتاح');
which means
alert('Enter opening price');
but when i save the .js file Dreamweaver says
and if I run the script browser says
this page contains
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and i am using a lot of text in arabic which works fine.
now how can I use alert for different language?
just add your script like this:
<script src="/js/intlTelInput.min.js" charset="utf-8"></script>
Just like any other text file, .js files have specific encodings they are saved in. This message means you are saving the .js file with a non-UTF8 encoding (probably ASCII), and so your non-ASCII characters never even make it to the disk.
That is, the problem is not at the level of HTML or <meta charset> or Content-Type headers, but instead a very basic issue of how your text file is saved to disk.
To fix this, you'll need to change the encoding that Dreamweaver saves files in. It looks like this page outlines how to do so; choose UTF8 without saving a Byte Order Mark (BOM). This Super User answer (to a somewhat-related question) even includes screenshots.
Try to put in the head section of your html the following:
<meta charset='utf-8'>
I think this need to be the fist in head section. More information about charset: Meta Charset
Same problem here, solved with this:
In Eclipse (with .js file open and on focus), go to, "File", "Properties", "Resource", "Text file encoding" choose "Other:" UTF-8, put correct characters code inside the code save your file and you are done!
I think you just need to make
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
Before calling your .js files or code
For others, I just had a similar problem and had to copy all code from my file, put it to simple notepad, save it with utf-8 coding and then replace my original file.
The problem at my side was caused by using PSpad editor.
The encoding for the page is not set correctly. Either add a header
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
or use set the appropriate http header.
Content-Type:text/html; charset=UTF-8
Firefox also allows you to change the encoding in View -> Character encoding.
If that's ok, I think javascript should handle UTF8 just fine.
This is a quite old request to reply but I want to give a short answer for newcommers. I had the same problem while working on an eight-languaged site. The problem is IDE based. The solution is to use Komodo Edit as code-editor. I tried many editors until I found one which doesnt change charset-settings of my pages. Dreamweaver (or almost all of others) change all pages code-page/charset settings whenever you change it for page. When you have changes in more than one page and have changed charset of any file then clicked "Save all", all open pages (including unchanged but assumed changed by editor because of charset) are silently re-assigned the new charset and all mismatching pages are broken down. I lost months on re-translating messages again and again until I discovered that Komodo Edit keeps settings separately for each file.
I too had this issue, I would copy the whole piece of code and put in Notepad, before pasting in Notepad, make sure you save the file type as ALL files and save the doc as utf-8 format. then you can paste your code and run, It should work. ?????? obiviously means unreadable characters.
RobW is right on the first comment.
You have to save the file in your IDE with encoding UTF-8.
I moved my alert from .js file to my .html file and this solved the issue cause Visual Studio saves .html with UTF-8 encoding.
I found a solution to my problem that seems like yours.
For some reason a script called from a external file doesn't works with charset="UTF-8", instead i had to use charset="ISO-8859-1" into script tag.
Now I'm after the "why it works?" reason.
thanks friends, after trying all and not getting desired result i think to use a hidden div with that arabic message and with jQuery fading affects solved the problem. Script I wrote is:
.js file
$('#enterOpeningPrice').fadeIn();
$('#enterOpeningPrice').fadeOut(10000);
.html file
<div id="enterOpeningPrice">
<p>أدخل سعر الافتتاح</p>
</div>
Thanks to all..
Related
I am referencing two JS files in my map.HTML header. Chrome console gives
Uncaught SyntaxError: Unexpected token <
Here is why I'm confused. When I click on the Chrome Console error message, it takes me to the Sources tab. Under Sources, it puts me on the relative JS tab, and shows code starting with < !DOCTYPE html> then continues with a ton of code that is not in my map.html file or JS file. Presumably this is generated when the JS is read?
The two JS files are:
https://github.com/socib/Leaflet.TimeDimension/tree/master/dist
https://github.com/calvinmetcalf/leaflet-ajax/tree/gh-pages/dist
I am opening map.HTML locally with Chrome using a simple python server using a batch file (python.exe -m http.server).
I am sure this is very basic, but it's confusing me because I reference plenty of other JS files both online and locally and I don't get this error.
Thanks
If you try https://github.com/socib/Leaflet.TimeDimension/blob/master/dist/leaflet.timedimension.min.js in your browser, you will get an HTML page.
If you try https://raw.githubusercontent.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js you will get what seams a source javascript file. But your browser may also consider it text/html, because that's what github sends in content-type header.
You can use third party sites which will serve files with appropriate content-type header, (example: https://rawgit.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js ).
In the future, try to do more research before posting here, otherwise a lot of people are going to downvote your questions, and even insult you.
A simple Google search for the differences between html and javascript may be a good start. The first step would be to remove those doctype lines. They mean nothing in Javascript. Just like the word granola has no meaning in Japanese. Different languages.
However, looking at your code, I don't see any DOCTYPE text in your javascript. In order to really debug this, you're going to want to open your webpage (html) in a browser (I recommend Chrome) and press F12 to open the developer tools. Go to the console and trace the error back through all of the files to find the origin.
In order to check and make sure that you're trying to pull javascript files and not html, take all the src urls you're using and paste them in a browser. If you land on a webpage, that url will serve up html, not javascript like you want. If you get a wall of text, you're probably referencing it correctly.
Correct: https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.js
Incorrect: https://github.com/socib/Leaflet.TimeDimension/blob/master/dist/leaflet.timedimension.min.js
Hopefully this helps before this question gets deleted or put on hold. Also notice that people are going to downvote me for actually answering and trying to help.
You can't directly reference code stored in a github repo like you're trying to.
The URLs you're listing aren't javascript files; they're github webpages. That's why they contain HTML doctypes and code you don't recognize -- it's the github website code.
You can get the URL for the actual javascript files by clicking the "raw" button at the top of any of those pages (after selecting a specific individual file -- the urls you gave were for directories, not individual files.) For example:
This is an HTML file: https://github.com/socib/Leaflet.TimeDimension/blob/master/dist/leaflet.timedimension.min.js
This is the raw javascript:
https://raw.githubusercontent.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js
(That said, I don't believe it's a good idea to treat github like a CDN; usually you would use that purely as a repository and host the actual files in use elsewhere.)
I have a web page displaying inside an iframe when I access it from from local machine:
http://localhost/mypage.html
it will display the following text correctly in spanish:
Búsqueda
But if I call it from my website
http://mywebsiteurl.com/mypage.html
I get the following:
Búsqueda
notice the ú has been replaced by ú I have tried changing fonts but the results are the same. The files on the web server are the same as on my localhost. Any ideas? Could it have something to do with my apache or php configuration may be difrerent than on my localhost machine?
in your html tag add the following
<html lang="es">
What you need might be
AddDefaultCharset UTF-8
in your .htaccess
For more insight check this thread How to change the default encoding to UTF-8 for Apache?
I have links in an html file like
href="%87%d9%84-%d9%8a%d9%86%d9%81%d8%b9-%d8%a7%d8%ae%d9%84%d9%89-%d8%a8%d8%b1%d9%86%d8%a7%d9%85%d8%ac-%d8%a7%d9%84%d9%85%d9%8a%d8%aa%d8%a7%d8%aa%d8%b1%d9%8a%d8%af-%d9%8a%d9%86%d8%a8%d9%87%d9%86%d9%89/index.html"
And I want when the user clicks on this link in the browser, the link will
be
RealUtf8Text/index.html
Is There any way to use it using .htaccess file ?
If not, how we can do it using a javascript file ?
I don't want to make changes in the files, just add .htaccess or javascript file and the problem is solved.
The problem appears to be that your URL does not contain valid UTF-8 data. There is no UTF-8 sequence that begins with the octet 87.
I'm guessing that your URL is missing a d9 or d8 octet. This URL:
http://localhost/%d9%87%d9%84-%d9%8a%d9%86%d9%81%d8%b9-%d8%a7%d8%ae%d9%84%d9%89-%d8%a8%d8%b1%d9%86%d8%a7%d9%85%d8%ac-%d8%a7%d9%84%d9%85%d9%8a%d8%aa%d8%a7%d8%aa%d8%b1%d9%8a%d8%af-%d9%8a%d9%86%d8%a8%d9%87%d9%86%d9%89/index.html
is shown as arabic characters in my browser:
How the URL is displayed will of course depend on the browser's support for arabic characters, and is not something that can be affected by JavaScript or .htaccess.
You use urldecode,
urldecode("%87%d9%84-%d9%8a%d9%86%d9%81%d8%b9-%d8%a7%d8%ae%d9%84%d9%89-%d8%a8%d8%b1%d9%86%d8%a7%d9%85%d8%ac-%d8%a7%d9%84%d9%85%d9%8a%d8%aa%d8%a7%d8%aa%d8%b1%d9%8a%d8%af-%d9%8a%d9%86%d8%a8%d9%87%d9%86%d9%89/index.html")
see the documentation in
http://php.net/manual/en/function.urldecode.php.
also make sure you have this on your html
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
New to ASP and probably never named a Javascript file ".inc" :-)
But that seems to be the norm where I'm currently working.
I observed that right on the first page I started getting these javascript errors
Message: 'globalVariableXXX' is undefined
I found that the javascript file wasn't getting called at all.
Just changed the name to ".js" and it worked !!
The ASP file includes the JavaScript file like this :
<SCRIPT LANGUAGE="Javascript" SRC="include/MenuCode.inc"></SCRIPT>
But there are 100's of these ".inc" files and 100's of references to them, hence don't want to go with this solution.
I'd rather understand it..
Any idea why it would've worked in the first place and why it isn't now ?
I'm sure I'm missing something pretty basic in ASP..
Another point : This application is installed on another server and it works just fine there when I hit it. I'm trying to install it on this new box.
Where I made the change for it to work:
In IIS, Right click on the name of the machine and the Mime Types are right over there. Checked the old server and it had the settings for ".inc", copied them and it started working :) Thanks all.
Maybe someone changed the webserver to prevent it serving .inc files ?
In the management console (inetmgr) right click the website and choose Properties. Go to "home directory" tab and click Configuration.
You will probably see the .inc extension there (in the mapping tab) meaning those files are parsed by the ASP engine.
Remove the item from the mappings table, apply and you should be able to parse those files as raw data.
The proper way to use a script tag for javascript is with the type attribute, such as
<script type="text/javascript" src="include/MenuCode.inc"></script>
see: http://www.w3schools.com/tags/tag_script.asp
language isn't even listed as a supported attribute by the standard..
Edit: The reason .js worked and .inc didn't is .js is in the mime type definitions of the server as a JAVASCRIPT mime type by default. If not using an extension configured as text/javascript by default, you have to tell the browser what to treat the file as somehow. This is why the text attribute of script is a required attribute as per html 4.01.
I have an HTML document stored in a file, with a UTF-8 encoding, and I want my extension to display this file in the browser, so I call loadURIWithFlags('file://' + file.path, flags, null, 'UTF-8', null); but it loads it as ISO-8859-1 instead of UTF-8. (I can tell because ISO-8859-1 is selected on the View>Character Encoding menu, and because non-breaking-space characters are showing up as an  followed by a space. If I switch to UTF-8 using the Character Encoding menu, then everything looks right.)
I tried including LOAD_FLAGS_BYPASS_CACHE and LOAD_FLAGS_CHARSET_CHANGE in the flags but that didn't seem to have any effect. I also checked that auto-detect was turned off, so that wasn't the problem either. Adding <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> to the document seems to have solved the problem, but I would expect that using the 'charset' argument of loadURIWithFlags should work just as well, so I'm wondering if I did something wrong in my initial attempt.
You did the right thing and the only solution is to include encoding information inside the document because if you rely only on HTTP headers you will fail to load the document when the document is saved on disk (because there is no such thing as headers for files).
If you are the one saving the file you could add the UTF-8 BOM to the file in order to assure that it will be properly loaded by Firefox or other applications.