Special character issue in page - javascript

Problem: Hi, this ‡ character is getting rendered correctly on my webapp.
I have tried using html entity as well but still its showing as ‡ Or ‡.

The caracter ‡ or maybe similar to not equal to (≠) , was a scpecial character.
And need another syntax, to be shown like that.
I can recommend you to use this line of code
<span style='font-size:100px;'>≠</span>
For more details, we can read this link of reference .
Hope it was helpful.
Thank you

Related

Javascript 'a' tag incorrect redirection

How come the following 'a' tag:
Redirects to the following wrong link?
(the correct link is 'https://www.ft.com/content/336e7f52-4189-11e8-93cf-67ac3a6482fd', but the url is redirected to 'file:///home/vincent/wintergreen/bokehIB/%E2%80%9Dhttps://www.ft.com/content/336e7f52-4189-11e8-93cf-67ac3a6482fd%E2%80%9D')
What could be the possible reason for that?
The full code describing the full creation of that page is here.
However, my code is python and bokeh package which is a bit niche, and I think that my problem is more of a javascript general thing - hence the reduced simple question.
Your anchor tag is Link here instead of Link here .
Notice that you have double double-quotes (") there.
You have " symbols surrounding your url, because it does not begin with a slash, it is considered relative url. try to remove these.

JavaScript: how to set a value containing quotes inside a textbox

I have an MVC-project where I store data in a database and one of my views contains textboxes to edit this data.
Because of the specifics I can't create the textboxes directly via TextBoxFor(), EditorFor() etc. but have to affect the value with JavaScript, so what i do is write the needed value in the javascript code at page loading, and this code is later on triggered to affect the textbox value.
$("#textboxID").val("#HTML.Raw(Model.value)");
This workes fine until one of strings has got quotes in it.
When i input it directly like
$("#textboxID").val("#Model.value");
it will be HTML-encoded with the quotes written as > & quot; (without space of cource)
What i found out is that the only way to output quotes correctly is by escaping them with backslash \ however i can't seem to find a helper to do that.
Is there a solution? Am i doing anything wrong?
For now, i found a workaround inspired by Filipe Borges suggestion
#Html.Raw(Html.Encode(Model.Libelle).Replace(""", "\\\""))
It's very ugly, but at least it solves the problem, I appreciate anyone suggesting a better solution.
For now, i found a workaround inspired by Filipe Borges suggestion
#Html.Raw(Html.Encode(Model.Libelle).Replace(""", "\\\""))
It's very ugly, but at least it solves the problem, I appreciate anyone suggesting a better solution.
Solved using:
#Html.Raw(Html.Encode(Model.value).Replace(""", "\\\""))
First suggested replacing " by \" using #Model.value.replace(""", "\\\""), but it does not work because the value only contains " after the default html encoding is applied by mvc.
Edit: Final solution by Souhaieb Besbes. Edited mine to not keep it wrong.
You can use single quote to show double quotes as following:
$("#textboxID").val('"'+#Model.value+'"');

Regular expression including two fixed strings and everything between

I'm not good at all in regex and I'm looking for an expression to get everything between and including either:
<script*/> OR
<script*</script> //asterisk refers to everything between
Basically, I want to copy sections from a single element for print but delete all tags and everything in between
A single statement that covers both scenarios would be preferable, but two solutions will work just fine
Any help will be greatly appreciated
This should work for both cases:
<script.*((/>)|(</script>))

Flip JQuery plugin not working

I'm making a website for a project, and I discovered and decided to use the, jquery flip plugin, and it's not working... I did manage to get it working a while ago, but couldn't since. Bear in mind I have not yet made the grafic part of the website yet, so what's there is just for show.
Here's the source code for the website.
No errors, just not working (fliping said boxes). As I said, it worked before, but when I added those other boxes, it stopped working.
Include jQuery UI before the Flip plugin. Since the Flip plugin needs jQuery UI to be available it probably fails when it's not.
It's always a good idea to use the demos on the plugin's documentation website as a template. The flip plugin includes the JS files in this order:
<script src="/lab/flip/js/jquery-ui-1.7.2.custom.min.js"></script>
<script src="/lab/flip/js/jquery.flip.min.js"></script>
Also, in your JSFIddle, you have to use absolute URLs for the resources, JSFiddle doesn't magically find jquery/jquery.flip.min.js.
Here is an updated version of your JSFiddle, I grabbed the above files from the plugin's documentation: http://jsfiddle.net/mNQJB/2/
If the above didn't fix your problem, there was an error with your code, one of the .flip calls had an invalid content property:
Uncaught SyntaxError: Unexpected token .
Make sure that your content properties are all on a single line or you have escaped the end-line characters properly.
Update
To escape an end-line character in JS we do this:
var str = "This is a string and \
I want it to use two lines.";
Notice the backslash, it's the standard escaping character. Now if you want to create a new line that will be rendered via HTML then you should use a <br /> tag:
var str = "This is a string and <br />I want it to use two lines.";
you have an unterminated string constant in this section:
$("#aimsb").bind("click",function(){
$("#aims").flip({
direction: 'bt',
color: '#39AB3E',
content: 'The aims of the GSP (Global Student Project) are to give students from all around the world both a culturally and personally enriching experience, as well as equal learning, and subsquently job opportunities
.'
});
});
note the line feed prior to the .'

Passing in a text to a javascript function that may have a single quote

I have a link that I dynamically create which looks something like the following:
<a onclick="Edit('value from a text column here')" href="javascript:void(null);">Edit</a>
with the Edit function then taking the passed in value and putting it into a Yahoo Rich Text Editor. This works well except for when there is a single quote in the text being passed. The obvious problem being that the link then looks something like:
<a onclick="Edit('I'm a jelly donut')" href="javascript:void(null);">Edit</a>
Any suggestions on what I can do? I'd rather not stray too far from the structure I am currently using because it is something of a standard (and maybe the standard sucks, but that's another question altogether).
Note: I am using ASP as my server side language.
Convert quote charaters to their HTML equivalents, " etc. before you insert them into the HTML. There's a long list of HTML/XML character codes on wikipedia.
There may well be a function to do this for you, depending on how you're dynamically generating the code: PHP has htmlspecialchars, and though I'm not familiar with ASP etc, I'm sure there are similar routines.
You could just replace the ' with \'
Run the text through an escape function to put a \ before the '. If you're generating the link on the server, we would need to know what server-side language you're using to give more specific advice.
If you're generating the tag client-side as a string in javascript (don't do that, use document.createElement), use the String.replace method on the argument string to pick out characters that will break the syntax you're generating and replace them with escaped versions.
I see at least three additional possibilities:
JavaScript Unicode escape
<a onclick="Edit('I\u0027m a jelly donut')" href="javascript:void(null);">Edit</a>
as \u0027 is the javascript espace character for the quote. The others being less practical:
JavaScript function
<script>function getQuote() { return "'" }</script>
<a onclick="Edit('I' + getQuote() + 'm a jelly donut')" href="javascript:void(null);">Edit</a>
and:
JavaScript global variable
<script>var g_strJellyText = "I\u0027m a jelly donut"</script>
<a onclick="Edit(g_strJellyText)" href="javascript:void(null);">Edit</a>
But I believe you already considered theses solution (or their variants, or the HTML entity escape mentionned by Chris Johnson).
Still, it's worth mentioning.
So it seems there was more going on, most of these would probably work under most circumstances, but in the interest of posterity here's what I had to do.
The information being pulled into the Rich Text Editor was in a YUI datatable and I am creating a link using the custom formatter prototype for said control.
The problem with using the "Replace ' with \' " method was that I need to still view the text being displayed in the datatable the same way.
The problem with using the ASP equivalent of htmlspecialchars (Server.HTMLEncode) was that it still had a problem in the javascript that was being generated from the custom formatter function. I don't know why exactly, but I did try it and it didn't work. That answer was closest to the answer that I came up with (and pushed me in the right direction) so I accepted that answer.
What I did instead was used the javascript function 'escape' to pass into my edit function, and then unescape to set the inner HTML for the Rich Text Editor.

Categories

Resources