I'm working on a new project and i want to do something similar (somehow) to intellitext ads (without popup though). In fact, i want to add links on certain words. The problem is that i don't know how to handle this.
I mean, ok, i get document.innerHTML then what? I can find any word, but some may be inside of tags. I don't want to replace words from textarea or text inside of a link. Same for input, select, and so on.
Also, the way i've managed things, i replace even the html tags (if the word is select for example, the script will replace <select> tag. And i really don't want this :P
So, any idea? Where to start ? What to do? Anything?
I wish a solution that works without any library, or, if is mandatory, to work with jquery (this is what i know).
I think that some regexp may help. The problem is... I never understand them :s
Any help will be appreciated. Thanks a lot!
jQuery does this already!
Just use .text() to get all the text underneath. Documentation and examples are here.
Related
I'm looking to test a text editor like https://github.com/brijeshb42/medium-draft using Cypress. But I can't find a way to select text using it. Does anyone have a clue on how to do that?
I'd have to select a specific text range in order for the test to be effective.
The commented answer above was the clue I needed, but it needs a couple tweaks (at least as of the version I'm using: v3.1.5). The link has all the info, but the answer should be as follows
cy.type('{selectall}')
Note that it's ".type()" instead of ".text()" and the escape sequence is quoted...
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+'"');
In a legacy application I'm working, somehow the jQuery scripts between
<script type="text/javascript"></script>
are being rendered as plain text instead of being executed.
Does someone have a suggestion of what can cause this behavior?
If you are using something like style : {display:block} it will behave like that.
Since we can not see all your code I will give you a few possible causes.
1.you could have forgot a closing tag for an element above it.
2.You could have forgot a pair of parenthesis on an element above.
3.You might have put the tag in a wrong spot so it might print depending on it's position.
Try to disable css. If it works fine after it, then you've styled tag 'script'.
Remember to read how to ask a question here on StackOverflow
But based on the little information given i'll make a longshot and think it might be something with parsing, read about CDATA
And check for unclosed html tags.
I am trying to build a specialized WYSIWYG text editor in the browser, and have a very limited set of functionality, but the biggest part of that is wrapping certain text in span tags.
I can find many resources explaining standard stuff (execCommand and whatnot), but have looked and looked and can't find anything to do what I need.
Basically, it's as simple as it sounds: user selects some text, clicks a button or whatever, and the text gets replaced with some other text (the initial case is that same text wrapped in some HTML tags).
I can find ways to do this in a textarea, but I'm just in regular HTML land, with the content in question inside a div with contentEditable marked as true.
I have also found ways to replace all occurences of text, or the first occurence, but not a specific one. Most solutions I find fail when trying to replace anything but the first occurence.
I'm hoping jQuery can do this in some way.
Have you tried the jQuery wrapSelection plugin?
This is pretty similar to this question. It might help.
I am having issues with an Ebay template, if I try to upload it get's kicked back to me saying that it cannot contain javascript, I'm assuming that it's in the picture rollover option (mouseover pic enlarging tool) Any help would be greatly appreciated, I'm not real Java intuitive.
Just delete anything between the <script> and </script> tags. Or perhaps post the code snippet here so we can tell you what to remove.
The template should have a HTML file inside.
Search for ... parts and remove them as mentioned before.
Search for instances of onmouseover="...", onmouseout="..." and generally anything that looks like , removing the onsomeevent="dosomething" part.