HTMLページでいくつかのHTMLコードをプレビューします。しかし、私がこれを行うと、ブラウザは実際のHTMLとして扱います(例えばタグを含む)。これを防ぐ方法を教えてください。
このページは、いくつかのHTMLの例を学習者に提示したいHTMLのチュートリアルと考えることができます。HTMLページでHTMLコードをプレビューする
答えて
<
の標識を<
に、>
の標識を>
に変えてください。
htmlspecialchars()
は、PHPでこれを行います。
それはうまく動作します。しかし、コード全体を変更する必要がない、より効率的な方法があるかどうかを知りたかっただけです。 –
私の知る限りではありません。 – ceejayoz
HTMLコードを「プレビュー」するのは、テキストエディタに入力するときに表示されるため、どういう意味なのか分かりません。おそらく、ページを訪問しているときに、Webブラウザで「ソースの表示」オプションを探していますか?
ブラウザがHTMLコードを摂取して解釈することを防ぎ、レンダリングではなくコードを表示することに興味がある場合は、htmlspecialchars()を使用できます。
ここには、レポートを書くために書いたJavaScriptモジュールがあります。ユーザーは、テキストエリアにHTMLまたはMarkdownを入力して、完成した結果を表示し、それらの間を切り替えることができます。
function Report (id) {
this.div = gel(id);
this.div.style.height = '100%';
this.trip;
}
//initializes the Report object and renders the HTML of the report to this.div
Report.prototype.init = function(trip) {
this.report = {'author':trip.owner,
'time_created':trip.time_created,
'title':trip.title,
'text':trip.summary,
'url':trip.url,
'category':trip.category,
'id':trip.id}
this.div.appendChild(this.renderHTML());
}
//show the edit form when the user clicks the edit link
Report.prototype.editForm = function() {
var r = this.report;
var form = dec('form');
form.action = '/trips/submit_link';
form.method = 'POST';
var t = dec('table');
t.style.width ='95%';
t.style.paddingBottom ='10px';
var tr = dec('tr');
t.appendChild(tr);
var td = dec('td');
td.style.width = '15%';
var strong = dec('strong');
strong.appendChild(dct('Title'));
td.appendChild(strong);
tr.appendChild(td);
td = dec('td');
td.style.width = '100%';
var input = dec('input');
input.type = 'text';
input.style.width = '100%';
input.className = "required"
input.name = 'reportTitle';
input.value = r.title;
td.appendChild(input);
tr.appendChild(td);
tr = dec('tr');
t.appendChild(tr);
td = dec('td');
var input = dec('input');
var strong = dec('strong');
strong.appendChild(dct('URL '));
td.appendChild(strong);
tr.appendChild(td);
td = dec('td');
input.type = 'text';
input.name = 'reportURL';
//input.className = "validate-url"
input.value = r.url;
input.style.width = '100%';
td.appendChild(input);
tr.appendChild(td);
form.appendChild(t);
var strong = dec('strong');
strong.appendChild(dct('Summary or Report '));
form.appendChild(strong);
var input = dec('textarea');
input.style.width = '96%';
input.style.height = '350px';
input.name = 'reportBody';
var converter = new Showdown.converter();
input.innerHTML = converter.makeHtml(r.text);
input.style.marginTop = "5px";
input.style.marginBottom = "5px";
form.appendChild(input);
var strong = dec('strong');
strong.appendChild(dct('Category'));
strong.style.marginRight = '10px';
form.appendChild(strong);
var input = dec('input');
input.type = 'text';
input.name = 'category';
input.style.width = '75%';
input.value = r.category;
form.appendChild(input);
form.appendChild(dec('br'));
form.appendChild(dec('br'));
input = dec('input');
input.type = 'submit';
input.value = 'Save';
input.style.cssFloat = 'left';
input.style.styleFloat = 'left';
input.style.fontWeight = 'bold';
form.appendChild(input);
input = dec('input');
input.type = 'button';
input.value = 'Cancel';
input.style.color = '#cc5500';
input.style.fontWeight = 'bold';
input.style.cssFloat = 'right';
input.style.styleFloat = 'right';
var self = this;
input.onclick = function() {
rac(self.div);
self.div.appendChild(self.renderHTML());
}
form.appendChild(input);
input = dec('input');
input.type = 'hidden';
input.name = 'tripID';
input.value = tripID;
form.appendChild(input);
return form;
}
//renders the HTML of the report to this.div
Report.prototype.renderHTML = function() {
var report = this.report
var rDiv = dec('div');
rDiv.style.height = '100%';
var h1 = dec ('h1')
if (report.url) {
var a = dec('a')
a.href = report.url;
a.target = '_blank';
a.appendChild(dct(report.title));
h1.appendChild(a);
var img = dec('img');
img.src = '/site_media/images/external_link.gif';
img.style.marginLeft = '5px';
h1.appendChild(img);
} else {
h1.appendChild(dct(report.title));
}
if (report.author == user) {
var a = dec('a');
var self = this;
a.onclick = function() {
rac(self.div);
self.div.appendChild(self.editForm());
attachToForms();
}
a.className = 'jLink';
a.appendChild(dct('(edit)'));
h1.appendChild(dct(' '));
h1.appendChild(a);
}
rDiv.appendChild(h1);
rDiv.appendChild(dct('Posted on '));
rDiv.appendChild(dct(report.time_created));
rDiv.appendChild(dct(' by '));
var a = dec('a');
a.href = '/user/' + report.author;
a.appendChild(dct(report.author));
rDiv.appendChild(a);
if (report.url) {
var div = dec('div');
div.style.color = 'green';
div.style.fontSize = '.8em';
div.appendChild(dct(report.url));
rDiv.appendChild(div);
}
rDiv.appendChild(dec('hr'));
var div = dec('div');
div.style.height = '75%';
div.style.overflowY = 'auto';
if (report.text) {
var converter = new Showdown.converter();
div.innerHTML = converter.makeHtml(report.text);
}
rDiv.appendChild(div)
rac(this.div)
this.div.appendChild(rDiv)
return rDiv;
}
- 1. 別のHTMLページ内のHTMLページのWebviewプレビューを作成する
- 2. ページのHTMLコード
- 3. htmlページでepsファイルをプレビューするには?
- 4. HTML:プレビューの直前にプレビューする
- 5. htmlページを読み込むhtml/javascriptコード
- 6. ブラウザでローカルHTMLファイルをプレビューする
- 7. C#でHTMLファイルをプレビューする方法
- 8. htmlビデオでの画像プレビュー
- 9. 既存のhtmlページにhtmlコードを追加するタスクをグループ
- 10. htmlファイルのプレビューを提供するカルーセル
- 11. HTMLページをHTMLページに含める
- 12. HTMLコードがページから流れ出る?
- 13. PHPコードは、WebページのHTMLコードを取得するには
- 14. HTMLページをXMLコードとして取得
- 15. jqueryページにHTMLコードを追加
- 16. htmlページにコードを表示したい
- 17. タブレットのWebページのHTMLコードを表示
- 18. ページURLからhtmlコードを削除
- 19. 「記事をプレビューする」でHTMLマークアップを無効にする
- 20. .HTMLページでASP.netコードを使用するには?
- 21. JavaScriptコードをHTMLコードで実行する
- 22. jsonオブジェクトをあるHTMLページから別のHTMLページに渡す
- 23. あるHTMLページから別のHTMLページにテキストフィールド値を渡す
- 24. そのは、HTMLページにHTMLページ内
- 25. netbean 8.1版でhtmlをプレビューするには?
- 26. サービス労働者、プリロードサブページ、私は次のコードでHTMLページへServiceWorker用HTML-コードを追加している
- 27. ページを再読み込みせずに、読み込まれたhtmlページにhtmlコードを挿入するには?
- 28. htmlページを印刷する
- 29. javascriptでHTMLコードを返す
- 30. 他のHTMLページでHTMLページの要素にアクセスできるようにする
SOエディタが動的に実行するか、またはサブミット/リフレッシュで静的に行うことができますか? –