Prevent automatic HTML special character encoding [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am working on a signature creator where you have some input fields and it generates an html page which you can use in Outlook as a signature. The problem is when there are special characters in 1 of the input fields, it will display some random characters ( e.g. é becomes é ). I've got some code to encode the special characters to html safe characters, but these get automatically converted back when injected in the html page. Is there a way to get the encoded characters into the html?
Here's jsfiddle of my problem (Open console in browser to view results):
https://jsfiddle.net/hdywwwf4/
This is what I want:
<h2 id="tester">ééé</h2>
This is what I get:
<h2 id="tester">ééé</h2>

Try using .innerText() to set the h2 content instead of .innerHTML()
This results in following element:
<h2 id="tester">&eacute;&eacute;&eacute; </h2>
https://jsfiddle.net/hdywwwf4/3/

Related

How can I store a block of text with links in my DB? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 11 months ago.
Improve this question
I have a textarea (as a description), I want to store the HTML code of the textarea in my db and I can convert the text to HTML with the "br" and "a" tags, the only ones I need. My problem is with the links that have &.
With JS, I tried to use btoa() method to encode the string, store it in my DB and decode with atob() when I want to show it but it gives me this error: Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
I resolved the problem with a string replace before inserting it in the table, and where I want to show, replace it again by &.

Regex pattern matching specific word [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a text input on my html page. When a user tries to add a new watch I want it to start with WATCH_XXXX (X's are whatever the user inputs). It has to start with WATCH_ all caps with the underscore. I've tried a lot of different ways but I keep getting the "please match the requested format" pop-up. This was the last one I tried -> required pattern="^WATCH_[a-z]". Am I even close to getting this right?
This regex ^WATCH_[a-zA-Z]+$ should work
<form>
<input required pattern="^WATCH_[a-zA-Z]+$"/>
<input type="submit"/>
</form>
Do all characters after "WATCH_" have to be letters? If not ^WATCH_.* may work better.
Tested here: https://regex101.com/#javascript
Also a great learning tool I use for Regex: http://regexone.com/

Get HTML <input> value in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I've searched arround on Google but couldn't find a clear answer on my question. The idea of what I want to do is quite simple:
There's a site called "glws.org" with a bunch of <div>'s and <input>'s on the page. You can add strings to the URL (example: https://glws.org/#S76561198105687636A2280482163D16883436630920468625) and for different strings after the # in the URL, different values are put into the <input>'s. The site reads the string after the # and has a script that converts it into values and puts the values in read-only <input>'s. Because they are <input>'s and not <p>'s for example, I can't just read them by printing out the HTML code.
Is there a way to retrieve the value in the input fields through a Java program? I've tried to read the source code of the page with Sockets but that obviously just prints the <input> tags without the value because it's not like a <p> or something.
Any help is appreciated!
You can use Selenium web driver to do browser actions on the website programatically and wait till some elements appear on the page.
https://code.google.com/p/selenium/wiki/GettingStarted

How and When can I use &lt or &gt? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm fairly new to Javascript, and just now learned about &lt and &gt. I don't how to use them or how they would look like in javascript. Can you give me an example? And is it better to use it than < or >?
< and > are HTML representations of the < and > characters. You should use them when creating HTML where you want these characters to appear. Otherwise, they are interpreted as syntactic elements by the HTML engine.
Suppose you have to dynamically create a text box in JavaScript and the contents of the textbox include something like "Do not forget to use <diamond brackets> in your HashMap declaration", i.e. any string that contains an opening or closing diamond (aka angle) bracket. Then here you will have to use < and >, else the browser will parse them as HTML tags and produce an erroneous page.

Adding special character in the end of the URL destroys webpage [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Why is the webpage destroyed when I add a special character to the URL, especially the /?
For example,
myproject.loc/page1.php/
How can I solve this?
Try to encode your URL while you are creating it. If the URL is gonna be created by javascript encode it by following command:
encodeURIComponent('myproject.loc/page1.php/"?');
or if you are creating URL in PHP use this:
urlencode('myproject.loc/page1.php/"?');
However it's not recommanded to use some special characters in a website URLs which want to follow SEO
When you put a trailing slash after page1.php your browser interprets it as a directory and it ruins all of your relative paths.
If you really want the trailing slash after a filename you would need to use apache url rewrites.

Categories