Print japanese with jQuery - javascript

I'm trying to print some Japanese to a page dynamically using jQuery, and it display nothing recognizable. I don't know what went wrong, I reduced the code to the most straight-forward, and it doesn't fix it. Or maybe it's just me being thick.
I use:
$('body').append('<p>日本語</p>');
Which should work, right?
And I get:
日本語
Huh?

Have you made sure that your page is set to use the Japanese character set? If not, make sure that your charset is defined in your <head></head> node :
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">

In some cases Utf-8 character set would be helpful. Add this in your Head node as below.
<head>
<meta charset="utf-8" />
</head>

Related

Powershell HTML Export is not working properly

I have another interesting mystery for you to solve.
Situation
I basicly use a PowerShell script to generate HTML pages. A meanigful example for this Powershell script would be as following: (Please note this is not the real complete code, but to understand the problem it should be enough)
function New-HTMLPage {
$htmlexport = #"
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Test</title>
</head>
<body>
...further HTML code blabla
"#
return $htmlexport
}
$htmlexport = New-HTMLPage
$htmlexport | Out-File -FilePath "C:\Test.html"
Today i tried to implement a Side Navigationbar into my HTML Code. For this Navigation i used JavaScript in my HTML which i imported like so within the body tag:
<script src="assets/js/sidebar.js"></script>
This is how the Sidebar looks like without powershell:
But when i generate this HTML Page with my Powershell Script (like the example above) it looks completly shredded.
=> Now the interesting part is, that when i copy the generated Powershell HTML Output and paste it into a clean HTML file it looks perfectly fine (like the first picture). Nothing shredded ?!
So my conclusion is, that it is wether a general HTML syntax problem nor a issue in powershell.
Does anyone have an idea what i am missing out or maybe what i can try to solve the issue ?
P.S: If you require any further information please do not hesitate to ask. I have deliberately not included every detail here so there are not too much information.
Thank you very much for your help!
Thank you very much to #mkelement,#jdweng,#Theo for providing this answer.
Finally the paramter -Encoding from the Out-File helped to sove the problem.
To find out the right encoding it followed the instructions from #Theo's comment.
Finally the correct CMDLet was:
Out-File -Encoding utf8 -FilePath "$Filepath"

How do I force browser to not show me smiley and instead show me unicode of the emoji?

I'm working on chrome Version 67.0.3396.99 and mac OS 10.13.5 (17F77). In my html, I don't want browser to convert an emoji to it's unicode text. I read this answer and it didn't help me much even if I added ︎. How can I do that?
First, I recommend to you, search for emojis in this page emojipedia, and then you only need copy and paste the emoji you want to use, make sure, you have
in your html head the <meta charset="UTF-8">:
<!DOCTYPE HTML>
<head>
<meta charset="utf-8">
</head>
<body>
😀
😋
<p>
Or just copy the emoji
</p>
😋
</body>

parsing html using Jsoup - returned document with robots meta tag

My problem is when I am using jsoup lib for parsing a specific url, it has been great till one day my parsing has corrupted, the document that has returned had some few tags which was not anything like the old document, it had meta tag named "ROBOTS".
An example of the header in the response:
<head>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="initial-scale=1.0" />
</head>
My question is, how do you think I can overcome this block? Tried using several other libraries which parse javascript as well, but it wasnt helpful and resulted the same, maybe I didn't use it right.
(I have learnt that the meta tag robots was made for preventing bots, initially for search engines, how can I bypass this behavior? How can I act like a regular every-browser client?)
You didn't explicitly state this in your answer, but I'm assuming Jsoup is being sent different HTML than what your browser sees. In that case, you probably need to set the user agent header so Jsoup looks like your browser.

Force String in JavaScript to be UTF-8?

my JS-File is UTF-8 encoded, my html document also.
I also have this in the head part of the HTML:
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
Every umlaut that I typed in the HTML is displayed properly.
But if I try to set a new value with $('#test').text('Test öäü') I get Test öäü.
How is this possible? Even console.debug/log and alert() display the same.
I also tried to set the charset attribute on my script-tag, but nothing worked.
Can anybody help me with this issue?
I found the issue. I use minify to combine my css/js and minify had $min_serveOptions['contentTypeCharset'] set to iso-8859-1.

getting weird symbols from yql

I'm requesting a website from yql using something like: select * from html where url="http://www.somerandomsite.com"&format=json&callback=process
The problem is I'm getting weird symbols back like: �
Is this because of yahoo or from the site that I'm using and how can I fix this?
You're probably missing a <meta> tag which defines the charset:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Categories

Resources