<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function sendToCart(a,b,c,d,f){
alert(arguments[1].replace(/'/g, "\\'"))
}
</script>
</head>
<body>
send to chart
</body>
</html>
can anyone please tell me why alert is not working? It is working fine when I directly escape while passing value at the time of onclick but not working after reading from function?
You will need to fix the server-side code to make sure you escape apostrophes. On server-side, depending on your server, you should have good means to escape apostrophes. If you are using PHP, you might want to call addslashes. Or you can call a method in your server-side which replaces apostrophe with \\'
The error occurs when the JavaScript parser reaches the s after the string literal 'Lover'.
Your escape function runs later (or would, if the syntax error hadn't stopped further execution).
You can't fix a syntax error in your JavaScript source code by trying to apply regular expressions to it, from inside the same program, after the parse error has already been hit.
Related
My page is located here
As you can see, it doesn't look like it's working properly. This becomes very apparent if you try to open it in an older browser (this is what initially set me off).
I checked the interpreted source code from chrome and it shows me the following:
<html>
<head>
<style type="text/css"></style>
</head>
<body>
<title>Internet adgang - Hurtig opsætning - Ansatte</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
Etc..
Something seems to be closing my head tag which is causing all SORTS of errors:
W3 validator
I have absolutely no idea what is causing this.
You can see my source code here (I've scrambled the PHP):
The code above does not contain my body code, as I am fairly sure that has nothing to do with the head tag closing all of a sudden.
Here is some source of a page that works just fine:
I am completely baffled by this and I have no idea what to do nor what is causing it.
Any ideas?
Solution
With the help of Buttc4k3 and vogomatix I finally found the solution. As buttc4k3 said, there was an illegal "zero-width no-space" character hidden in the file which didn't show in my sublime text editor. It would only show if you opened the file in Notepad++. I could not understand why this character would appear in google chrome, and not in my source, but after googling it, I found that a file saved in UTF-8 WITH BOM (Byte Order Marking) would save the BOM as a zero-width no-space character! This was where vogomatix saved me and told me that my file was saved with BOM and after recoding it without BOM it works fine.
So - if you have the same problem as me - save your file WITHOUT BOM ENCODING (this can be done in notepad++).
I took the page source of your website and pasted it in Notepad++ and found a zero-width no-break space in line 3 column 5. It renders invisible in most editors/viewers, but it breaks the HTML parser of the browser. I don't know how or why it got there since I can't find it in the PHP code, but maybe you can find it by opening your code in Notepad++. It renders this character as a tiny dot. If you can't find it, delete everything from and including <head> to <title> and re-type it.
I hope this works.
PS: Even though it is not the reason why your page is broken, you should add <html> and </html> to the markup. Most browsers can deal with its absence, but it is there for a reason.
It seems like you are missing the <html> tag.
Current HTML-Code:
<!DOCTYPE html>
<head>
<title>Internet adgang - Hurtig opsætning - Ansatte</title>
Must be something like that:
<!DOCTYPE html>
<html>
<head>
<title>Internet adgang - Hurtig opsætning - Ansatte</title>
[...]
</head>
<body>
[...]
</body>
</html>
Edit the first part of your site to be as follows:
<?php
include 'XXXXX';
include 'XXXXX';
if(!isset($_GET['lang'])) {
$lang = "DA";
} else {
$lang = $_GET['lang'];
}
?>
<!DOCTYPE html>
<html lang="<?php $lang; ?>">
<head>
<title><?php echo trans("Internet adgang - Hurtig opsætning - Ansatte", $lang); ?></title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="resources/styles/style.css" media="all">
<script src="resources/js/jquery.min.js" type="text/javascript"></script>
<script src="resources/js/jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="resources/styles/au-flowbox-style.css">
<script type="text/javascript" src="resources/js/au-flowbox.js"></script>
<script type="text/javascript" src="resources/js/au-flowbox.data.js"></script>
</head>
<body>
....
I've recently ran into a problem and I would really use a bit of help from the community. I'm trying to load a HTML file using jQuery load().
The index file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Question</title>
<meta http-equiv="Content-Type" Content="text/html; charset=euc-kr" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function restart(){
$("#wrap").load('new-content.html').hide().fadeIn('slow');
}
</script>
</head>
<body>
<div id="wrap">
<div id="content">Text before restart: 남성</div>
</div>
<br />
Restart
</body>
</html>
The new HTML file includes some simple HTML content and a call to a .js file (used for some animations). The new content file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Question</title>
<meta http-equiv="Content-Type" Content="text/html; charset=euc-kr" />
<script src="main.js" language="javascript" type="text/javascript" />
</head>
<body>
<div id="contentInner">Text after restart: 여성</div>
</body>
</html>
As you can see I've included the correct encoding charsets (for both files) and I've double checked and I can confirm that every file used for this part of the code it's encoded as "KOREAN" (checked in different apps like Dreamweaver, Notepad++, Sublime Text 2).
Yet still once I load the content the characters are not encoded properly; question marks appearing instead of characters.
Of course I made some searching before posting and I found a few helpful topics about this called the PHP header solution, but this isn't an options since it need to use HTML/JS/CSS only.
The same behavior occurs when I'm using the Japanese language too. In other latin based languages everything is working perfectly fine of course.
Any sort of input/advice/help would be much much appreciated.
Thank you!
This is the file I am trying to run, but all it does is open the web page with the page title, it doesn't run the script.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html lang=”EN” dir=”ltr” xmlns=”http://www.w3.org/1999/
xhtml”>
<head>
<meta http-equiv=»content-type» content=»text/xml;
charset=utf-8» />
<title>HelloWorld.html</title>
<script type = «text/javascript»>
//<![CDATA[
// Hello, world!
alert(«Hello, World!»);
//]]>
</script>
</head>
<body>
</body>
</html>
I tried running on aptana and notepad, neither show the dialog box. I feel like I am forgetting a small yet significantly important part?
Your quotes are a combination of angled quotes (« and ») and smart quotes (“ and ”). You need "regular" quotes, ", in both HTML and JavaScript. If your keyboard is automatically configured to do that replacement somehow, try using single quotes instead, or just swapping keyboard layouts for coding.
You need to enclose single ' ' or double " " instead of « ».
Here is the corrected codes,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/
xhtml">
<head>
<meta http-equiv="content-type" content="text/xml; charset=utf-8" />
<title>HelloWorld.html</title>
<script type = "text/javascript">
//<![CDATA[
// Hello, world!
alert("Hello, World!");
//]]>
</script>
</head>
<body>
</body>
</html>
I have a similar problem to this: jQuery AJAX Character Encoding but any solution mentioned there works for me.
I've made three easy files to show the problem:
PHP File:
//prueba.php
echo "nº one two € áéíóú";
JavaScript File (I use JQuery)
//Javascript file
function prueba() {
$.ajax({
type: "GET",
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-1",
url: "prueba.php",
}).done(function( data ) {
$("#prueba").text(data);
//$("#prueba").html(data); //It does the same encoding error
});
}
** HTML File:**
<html>
<head>
<title>E-COMMERCE</title>
<meta content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script src="javascript/jquery.js" type="text/javascript"></script>
<script src="javascript/javascript.js" type="text/javascript"></script>
</head>
<body>
Prueba
<div id="prueba"></div>
</body>
</html>
And when you click the link Prueba it shows:
Prueba
n� uno dos � �����
The current website works perfectly but it does not use ajax and it is in the same server where i am doing this, so How can I tell to jquery to return ISO-8859-1 instead of whatever it is returning? I know that the ideal is to use always utf-8 but changing to utf-8 it will give us some problems we cant afford right now.
To make the browser use the correct encoding, you have to add an HTTP header to the php page :
header("Content-Type: text/plain; charset=ISO-8859-1");
or you could put the encoding in a meta tag of the html:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
In your php file you'll need to UTF-8 encode the output:
echo utf8_encode("nº one two € áéíóú");
And then in your html file you will need to set the charset:
<html>
<head>
<meta charset="utf-8"/>
...
And for good practice specify a document type as well:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
...
<!DOCTYPE html> is a legit HTML5 doctype.
And as Pranav Kapoor pointed out maybe you will need to specify the PHP-file charset aswell:
header("Content-Type: text/plain; charset=UTF-8");
I can see you have specified your charset to: ISO-8859-1. I always work with UTF-8 You can read more about it here: What is the difference between UTF-8 and ISO-8859-1?
But remove the contentType from your ajax call
i am making some script for some personal use. Now i tend to keep my CD collection list in a html file which has some sleek design, but i am tired of editing the list by "hand" and that means that i don't want to edit the code everytime i add new CD. So is there a way that i can use JS or JQuery so i could add/read from a local file(this script is not remote it is local(although i might try to host it remote).
I don't want to use any other language than HTML, CSS and JS/JQuery.
EDIT: Is it possible to add a link that when i click some application on my computer would launch.
Not if you only want to use HTML and javascript. You will need a server side script of some kind to write to a file.
The comments got me thinking, I know this is not really what you were asking but you could play around with server side javascript with node.js
You can do it like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CD Collection</title>
<script type="text/javascript" charset="utf-8" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
var cds = ['cd1', 'cd2', 'cd3'];
$(function() {
$(cds).each(function() {
$('#cd_list').append('<li>' + this + '</li>')
});
});
</script>
</head>
<body>
<p>
<ul id="cd_list"></ul>
</p>
</body>
</html>
The inline js with the cd list can be loaded in as a separate file in the same way jquery was pulled in.