I am using Html, Jquery and Javascript. I am using linkify javascript library and is working fine. But if there is no space before the URL then it does not work. How to solve this? I have below URL along with text.
Please click the linkhttp://www.asdfgh.com
Please see there is no space before the URL. How to linkify the URL here?Can it be done using Javascript?
don't Know linkify. Maybe there is an option for setting individual patterns.
Otherways you could search the text for this string and replace it, before linkify do its work. But its dirty.
yourtext=yourtext.replace("linkhttp://","link http://");
Related
I am creating a link URL in my website and using it in the blog as href for anchor tag.
This is how my URL looks in website
https://www.mywebsite.com/sets/get-the-look-bella-hadid---london/4558
After passing it to the blog the link parse to something like this
https://www.obsessory.com/sets/get-the-look-bella-hadid—london/4558
I don't understand why is it converting --- to — ?
Have anybody faced same problem anywhere ?
People voting to close the question, try and understand the question.
I guess you are using WordPress? The editor for text handles hypens and dashes automatically - as many other editors out there do.
https://codex.wordpress.org/Function_Reference/wptexturize this is doing the magic in WordPress.
You might need to insert your link as link instead. See https://en.support.wordpress.com/links/
Or in functions.php you can disable the magic (but a real link is the better choice):
remove_filter( 'the_title', 'wptexturize' );
remove_filter( 'the_excerpt', 'wptexturize' );
remove_filter( 'the_content', 'wptexturize' );
This isn't really a programming problem (and therefore, isn't appropriate for StackOverflow), it's a problem with your blogging software.
You're most likely pasting the text into a rich text editor like WordPress has and it's converting the text on you. The problem is, WordPress and other software try to convert raw URLs into links, but they also try to make the content pretty. By prettifying the content, it's converted multiple dashes into an em dash. Then, when it tries to turn that into a link, it only gets part way because the em dash is not a valid URL character.
To work around it, don't rely on the editor to convert links for you. Write some text you'd like for the link, highlight it, then use whatever "link" button is in the editor to make it an actual link.
You might also be able to use a raw HTML editor or a Markdown editor (like StackOverflow has) to craft the link properly.
I'm trying to have a textarea input field just like when you post a new StackOverflow question. You can have line spaces, you can bold text, you can insert link etc.
However, when you push some kind of button, all of that gets translated into a long HTML string (e.g., spaces become <p> or <br>, bold becomes <strong>, link becomes <a>). Is there a way to do this with some kind of JS plug in?
What you describe is a What You See Is What You Get (WYSIWYG) editor.
Google "WYSIWYG editor library"
Examples:
https://prosemirror.net/
https://www.tinymce.com/
This question has been answered here Rendering HTML inside textarea
What you need is WYSIWYG (What you see is what you get) editor.
There are a lot of them.
You can check out these:
Ckeditor The best web editor for everyone
TinyMCE Full featured web editing
They are very easy to use.
If I have understood what you are asking, you will need to learn regular expressions. Everything is the context is based on text replacement.
Example: because textarea does not display hyperlinks, buttons, i can do somethings like in stackoverflow.
For hyperlink, i can write something link [# http://facebook.com] or [link]http://facebook.com [link];
later, I extract the http://facebook.com and wrap it between <a></a> elements.
What everybody above said is true, you want to be looking at a WISYWG editor.
If by chance you are using Bootstrap, you may want to look at Summernote.
I have no affiliation with them, but I used it for one of my projects and was very pleased.
I just had a question about the regex object in javascript...
My regex is this:
data-href="[^"\r\n]*"
when I use it in this site:
http://www.regular-expressions.info/javascriptexample.html
matching against the following string:
<div class="fb-like" data-href="http://example.org" data-send="true" data-layout="box_count"
it tests positive and returns the url. My goal is to dynamically change the value of data-href parameter for the div using javascript to dynamically include the anchors of the webpage (the site Im working on uses an ajax based navigation dependent on # anchors in the url).... And i really want the facebook button to be mutable so that when a person clicks "like", they dont just "like" the homepage.
how would I do that?
I tried various tutorials but couldn't get the regex to match at all (it always returned false).
where should I start?
thx!!!
You can change the attribute using jQuery or any other JS-Framework. Then you don't need any regex. This
$(".fb-like").attr("data-href", window.location.href);
should do it.
as it turns out the facebook button doesn't actually use the data-href attribute to specify the link it is going to use for its integration. My complete and fundamental misunderstanding.
Looks like it figures that out independently using a referrer or figures out what domain its script is running from... anyway, sorry about the hassle.
I am trying to do something the following:
$("#link_id").click(function() {
$.modal('<div class="framed-view"><iframe src="http://domain.com/stuff#12"/></div>');
});
Using the jQuery simplemodal plugin.
However, when I click that link - the link that is displayed is:
http://domain.com/stuff
rather than
http://domain.com/stuff#12
Does anyone know why the iframe would be ignoring everything after the hash tag?
The problem is that this HTML is in JavaScript and must be properly escaped when certain characters conflict with standard JS characters.
Escape the hashtag using \ as this user did. JavaScript function if url has hash tag and user has just navigated forward or back with browser?
You may also need to escape / characters as well.
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.