Thursday, July 26, 2012

javascript – converting html tags and the content to string



my question is I need to create a string from the result of event.content. Event.content returns me an entry including html tags. I can use it like container.innerHTML = event.content. I need the event.content as a string. I tried to do something like this:



var a = \'\' + event.content;


But it doesn\’t work. Here the result of event.content:



<img src=\"http://image.weather.com/web/common/wxicons/31/30.gif?12122006\" alt=\"\" />Partly Cloudy, and 84 &deg; F. For more details?


I can\’t convert this into string in javascript. Is it possible? I also tried String(event.content). Ok I put my whole code.



<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=ISO-8859-1\">
<title>Hava Durumu</title>

<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>
<script type=\"text/javascript\">

google.load(\"feeds\", \"1\");
function havabas(){

var feed = new google.feeds.Feed(\"http://rss.weather.com/weather/rss/local/TUXX0014? cm_ven=LWO&cm_cat=rss&par=LWO_rss\");
feed.load(function(result) {
if (!result.error) {
var entry = result.feed.entries[0];
var container = document.getElementById(\"weather\");
var c = entry.content;

var regex = /<img.*?src=\"(.*?)\".*?>.*?([0-9]+\\s*&deg;)/;
var results = regex.exec(entry.content);
var html = \'<img src= \' + results[1] + \' alt=\"\" /> \' + results[2];

container.innerHTML = html;

}
});
}

function initialize() {
havabas();
setInterval(function(){havabas()},2000);
}
google.setOnLoadCallback(initialize);

</script>
</head>
<body>
<div id=\"weather\"></div>
</body>
</html>






Rating: 3 out of 5 based on 3 ratings



The post javascript – converting html tags and the content to string appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-converting-html-tags-and-the-content-to-string.html

No comments:

Post a Comment