I'm trying to use the card validator (Twitter validator) in twitter. I have my code in the variable called content all my other code is working, but the twitter meta tags. I have the quotes of the tags like \" but when I do this the twitter validator doesn't show my card properly.
If I remove the \ then the rest of my code doesn't work properly. Is there a way to escape the quote so that the twitter card validator will accept it and read the meta tags.
HTML code:
<html>
<body>
Image link: <input type="text" id="img">
Content: <input type="text" id="content">
<button onclick="makePage()">click</button>
<script src="makePage.js">
</script>
<script>
var img = document.getElementById("img").value;
var content = document.getElementById("content").value;
</script>
</body>
</html>
Javascript code. The html is in the content variable.
function makePage(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200)
alert("webpage " + xmlhttp.responseText + " was successfully created!");
}
var content = '<html><head></head><body><meta name="twitter:card" content="summary_large_image"><meta name="twitter:site" content="@nytimes"><meta name="twitter:creator" content="@SarahMaslinNir"><meta name="twitter:title" content="Parade of Fans for Houston’s Funeral"><meta name="twitter:description" content="NEWARK - The guest list and parade of limousines with celebrities emerging from them seemed more suited to a red carpet event in Hollywood or New York than than a gritty stretch of Sussex Avenue near the former site of the James M. Baxter Terrace public housing project here."><meta name="twitter:image" content=""></body></html>';
xmlhttp.open("GET","makePage.php?content=" + content,true);
xmlhttp.send();}
My PHP code (I'm dynamically making pages):
<?php
$content = $_GET["content"];
$file = "" . uniqid() . ".html";
file_put_contents($file, $content);
echo $file;
?>
The error the Twitter validator is giving:
INFO: Page fetched successfully
INFO: 8 metatags were found
WARN: Not whitelisted
I know that it says 'Not whitelisted', but my website is white listed (it works on the main page). I'm sure this is being caused due to the nested quotes.