I create a site in pure HTML (css), can you tell me how to automate the addition of news to the site without using various engines?
Closed due to the fact that the issue is too common for the participants D-side , Bald , Kromster , Denis Bubnov , Denis 21 Dec '16 at 7:10 .
Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .
- Much depends on where and how you receive news (which API is provided by your chosen news source). If you take Yandex.News as an example ( news.yandex.ru/export.html ), then it all comes down to adding simple JavaScript code to your page followed by page styling. - stanislav
- There will be time, please give an example of Java. Yoda, I will write news myself. Viktor, I do not ask for it. I'm interested in automation. - Zione
- Surely even just a script on the PCP is not accepted? Only pure HTML? - ichbinkubik
- Kubeev Arman, most likely, I will do with the help of PHP, there is really no other option. Yes, I wanted it on pure html-css, as I don’t know php. - Zione
- And the rss-file does not roll? - Dimamur
6 answers
You can create pages in Microsoft Office and save them in HTML format and make the world a better place .
- And you can write a macro that will generate all the necessary pages and pump a ton of them to the site each time. - Sergey
There is a cool technology of asynchronous programming ajax) There is a good jQuery framework) Well, here you can create an html file "news.html", where to place news in containers with the class "new". In your, for example, the main page of the site in the head tag, connect the jQuery and the future news script, where the function of displaying news on the page will be placed:
function news() { $.ajax( url: '/news.html', type: 'GET', dataType: 'html', success: function(data){ $(data).find('.new').each(function() { $('#newslist').append('<div>'+$(this).html()+'</div>') }) }) }
where '#newslist' is the block identifier into which all news blocks with the class '.new' from the document '/news.html' will be output.
And the function call:
$(document).ready(function(){news()})
This scheme works like this: your document is loaded; when the browser parser finishes with DOM, our script will work. First, it downloads the news page to your browser in the background, then finds the news blocks in it and inserts them into the news output block in the column.
Let javascript read the text from the file and output it in the div. )
- Eugene, please provide a JavaScript code that reads text from a file. - Evgeniy
- It is not able to read js from a file, it is more precisely able only through ActiveX (which is only under u). But you can pervert and make dynamic loading of js files into head, in which json (for example) stores news. - Alex Silaev
- Tomorrow I will try to give an example. Everything is at work. ) - Eugene
In general, you need to make a file news.js There to write something like: news = "Text news." Then in another js file, write a script that will be from this file, from a variable, take the news. You can make an array. )
- And where is the reading javascript text from the file? - Viktor
- Well done :) I wrote about this :) "Reading from a file" and "loading a file" are different things, if that :))) - Alex Silaev
As an option, pull up the news from the js-file and display them using functions. An example is:
var news = [], i = 0; news[i++] = {'date': '05.03.2012', 'title': 'new new', 'text': 'Lorem Ipsum Dolor Sit Amet.'}; news[i++] = {'date': '06.03.2012', 'title': 'new new 2', 'text': 'Lorem2 Ipsum2 Dolor2 Sit2 Amet2.'}; function showNews(id, news){ // на входе - id контейнера новостей и массив новостей var id = document.getElementById(id); var tpl = '<div class="new">%date% - %title%<br />%text%</div>'; // шаблон одной строки var html = ''; if(id){ for(var i = 0, il = news.length; i < il; ++i){ var ahtml = tpl; // берем шаблон и подставляем значения ahtml = ahtml.replace(/%date%/g, news[i].date); ahtml = ahtml.replace(/%title%/g, news[i].title); ahtml = ahtml.replace(/%text%/g, news[i].text); html += ahtml; } id.innerHTML = html; } }
Here is an example of news that I use: the news.js file:
document.write('<br>20.06.2011 г.<br>'); document.write('<b>Добавлены новые халаты и фото к ним <a class="spisok" href="../rab_odegda/rab_odegda.html">(ЗДЕСЬ)</a></b><br>'); document.write('<br>15.06.2011 г.<br>'); document.write('<b>Добавлены фото продукции <a class="spisok" href="../rab_odegda/rab_odegda.html">(ЗДЕСЬ)</a></b><br>');
and this is how I call him to the village (it scrolls through me):
<tr> <td width="198" style="border-left:#4d4d4d 1px solid; border-top:#4d4d4d 0px solid; border-right:#4d4d4d 1px solid; border-bottom:#4d4d4d 1px solid; font-family:Tahoma; font-size: 11px; color:#af0e0e; font-weight:bold; padding-left:3; padding-top:5; padding-right:0; padding-bottom:5" height="100" align="Left"> <MARQUEE onmouseover=this.stop() onmouseout=this.start() scrollAmount=1 scrollDelay=20 direction=up height="120" > <script language="JavaScript" src="img/news.js" width height></script> </MARQUEE> </td> </tr>
I change only news.js and everything, I throw it on a server - the news has been updated