Hi allemaal,
Ik heb een scriptje gemaakt, en probeer in de return html te tonen.
Zodra ik het bekijk in mijn browser komt het er niet uit als een HTML code maar als:PHP Code:
if(this.match('(logo|Where can I download the logo\'s)'))
return "<a href='https://test.nl'>test</a>";
Iemand een idee wat ik fout doe?PHP Code:
<div class="party other"><a href='https://test.nl'>test</a></div>
- Vraag over javascript
-
29-12-2018, 02:35 #1
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Vraag over javascript
-
In de schijnwerper
Lokale links uit je regio/stad | Blogs - Regionale bekendheid & Sterke linksOverige dealsPrijsperkwh.nl - met content & affiliate kansenWebsite te koopSpraakcomputers.nl - Premium domeinnaam - Medisch / communicatiemiddelenDomein te koopZeer ervaren programmeur beschikbaar | web, api & appFreelance / Werk -
29-12-2018, 09:05 #2
- Berichten
- 11
- Lid sinds
- 11 Jaar
Re: Vraag over javascript
Hallo Stefan,
De returnstring wordt gezien als tekst, dus een \ voor je html open en sluit tags zou het op moeten lossen.
De returnstring wordt dan dus : "\<a href='https://test.nl'\>test\</a\>"
-
29-12-2018, 10:42 #3
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
-
29-12-2018, 12:24 #4
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Re: Vraag over javascript
Mocht iemand er vandaag tijd voor hebben, heb ik er ook wel een kleine vergoeding voor over.
-
29-12-2018, 13:19 #5
64BitsWebhosting.EU
- Berichten
- 2.085
- Lid sinds
- 18 Jaar
Re: Vraag over javascript
Waarschijnlijk doe je nog ergens een htmlspecialchars() om de waarde die je retourneert en voordat ie op het scherm getoond wordt.
Dat is normaal gesproken ook goed indien het user supplied values zijn, maar bij eigen gecontroleerde return waarden, zou je die htmlspecialchars() dan niet moeten doen.
-
29-12-2018, 13:28 #6
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Re: Vraag over javascript
Waarschijnlijk doe je nog ergens een htmlspecialchars() om de waarde die je retourneert en voordat ie op het scherm getoond wordt.
Dat is normaal gesproken ook goed indien het user supplied values zijn, maar bij eigen gecontroleerde return waarden, zou je die htmlspecialchars() dan niet moeten doen.
PHP Code:/* ---------- CHAT BOT ENGINE JS ----------- */
function chatBot() {
// current user input
this.input;
/**
* respondTo
*
* return nothing to skip response
* return string for one response
* return array of strings for multiple responses
*
* @param input - input chat string
* @return reply of chat-bot
*/
this.respondTo = function(input) {
this.input = input.toLowerCase();
if(this.match('(hi|hello|hey|hola|howdy)(\\s|!|\\.|$)'))
return "Hi there, how can I help you?";
if(this.match('(ok|thank you|merci)'))
return "\<a href=\"https://test.nl\">test\</a\>";
if(this.match('(test)'))
return ["It's working!", "How can I help you?"];
if(this.match('what[^ ]* up') || this.match('sup') || this.match('how are you'))
return "this github thing is pretty cool, huh?";
if(this.match('l(ol)+') || this.match('(ha)+(h|$)') || this.match('lmao'))
return "what's so funny?";
if(this.match('^no+(\\s|!|\\.|$)'))
return "don't be such a negative nancy :(";
if(this.match('(cya|bye|see ya|ttyl|talk to you later)'))
return ["alright, see you around", "good teamwork!"];
if(this.match('(dumb|stupid|is that all)'))
return ["hey i'm just a proof of concept", "you can make me smarter if you'd like"];
if(this.input == 'noop')
return;
return ["I didn't get that, can you rephrase your question?"];
};
/**
* match
*
* @param regex - regex string to match
* @return boolean - whether or not the input string matches the regex
*/
this.match = function(regex) {
return new RegExp(regex).test(this.input);
};
}
/* ---------- START INDEX JS ----------- */
$(function() {
// chat aliases
var you = 'You';
var robot = 'bot';
// slow reply by 400 to 800 ms
var delayStart = 800;
var delayEnd = 1000;
// initialize
var bot = new chatBot();
var chat = $('.chat');
var waiting = 0;
$('.busy').text(robot + ' is typing...');
// submit user input and get chat-bot's reply
var submitChat = function() {
var input = $('.input input').val();
if(input == '') return;
$('.input input').val('');
updateChat(you, input);
var reply = bot.respondTo(input);
if(reply == null) return;
var latency = Math.floor((Math.random() * (delayEnd - delayStart)) + delayStart);
$('.busy').css('display', 'block');
waiting++;
setTimeout( function() {
if(typeof reply === 'string') {
updateChat(robot, reply);
} else {
for(var r in reply) {
updateChat(robot, reply[r]);
}
}
if(--waiting == 0) $('.busy').css('display', 'none');
}, latency);
};
// add a new line to the chat
var updateChat = function(party, text) {
var style = 'you';
if(party != you) {
style = 'other';
}
var line = $('<div><div class="party"></div></div><div class="clearfix"></div>');
line.find('.party').addClass(style).text(party + '').text(text);
chat.append(line);
chat.stop().animate({ scrollTop: chat.prop("scrollHeight")});
};
// event binding
$('.input').bind('keydown', function(e) {
if(e.keyCode == 13) {
submitChat();
}
});
$('.input a').bind('click', submitChat);
// initial chat state
updateChat(robot, 'Hi there! I\'m the chatbot');
});
-
29-12-2018, 15:08 #7
- Berichten
- 1.410
- Lid sinds
- 16 Jaar
Re: Vraag over javascript
Je voegt de code in met $(element).text("<b>test</b>"); Deze jQuery functie zorgt ervoor dat je input ook tekst is ipv html.
Wat je moet doen is $(element).html("<b>test</b>");
Als ik zo vluchtig even door je code scan is het deze regel:
Code:line.find('.party').addClass(style).text(party + '').text(text);
Code:line.find('.party').addClass(style).text(party + '').html(text);
http://api.jquery.com/html/
en
http://api.jquery.com/text/
-
29-12-2018, 15:31 #8
- Berichten
- 1.735
- Lid sinds
- 17 Jaar
Re: Vraag over javascript
Je voegt de code in met $(element).text("<b>test</b>"); Deze jQuery functie zorgt ervoor dat je input ook tekst is ipv html.
Wat je moet doen is $(element).html("<b>test</b>");
Als ik zo vluchtig even door je code scan is het deze regel:
Code:line.find('.party').addClass(style).text(party + '').text(text);
Code:line.find('.party').addClass(style).text(party + '').html(text);
http://api.jquery.com/html/
en
http://api.jquery.com/text/
-
29-12-2018, 21:07 #9
- Berichten
- 1.410
- Lid sinds
- 16 Jaar
Re: Vraag over javascript
Haha geen dank ;-)
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic