-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem linking urls with content editable and IE #61
Comments
Hey Samuel. Can you describe the problem you're having in more detail? What do you mean that Internet Explorer imminently creates an html link when you type one? Where are you typing in text that causes IE to automatically link things? (text field / text area? rich text editor? etc) |
Thanks for your quick reply! Administrators on my website are able to edit the text on some pages. I'm doing this with content editable div's, and I safe the data to my database with javascript. I am applying autolink to the data just before I safe it to the database, inside the database the links are already autolinked. |
Dear gregjacobs, This still is a problem for me and it still doesn't work. Could you please try to look into this problem? |
Hey, sorry dude, do need some more info. Can you paste what your text looks like before it is sent to Autolinker, and what it looks like after? Would be useful to see the input text from Chrome/Firefox vs. Safari/Internet Explorer too. |
Ah, ok, now I'm understanding. So Internet Explorer automatically creates the links for you from the content editable field, and therefore Autolinker is ignoring them. What you might try doing is removing the IE-generated anchor tags using your browser's DOM before running Autolinker on it. Are you using any libraries? Using jQuery to unwrap the var $contentEl = $( '#elementWithContent' );
// Find all anchor tags within the content, and replace them with just their href's,
// in preparation to be autolinked using Autolinker's settings
$contentEl.find( 'a' ).each( function( i, elem ) {
$( elem ).replaceWith( elem.href );
} );
var autolinkedHtml = Autolinker.link( $contentEl.html() ); If you're not using jQuery (and are having trouble), let me know and I'll come up with something else :) |
Thanks for your great help! I am using jQuery. As you can see, I used my own variable which has the html content from the DIV. I don't know if this causes any problems (pretty new to jQuery :)) but I can't find out why it would be a problem. Verzonden vanaf mijn Samsung Galaxy smartphone. -------- Oorspronkelijk bericht -------- Ah, ok, now I'm understanding. So Internet Explorer automatically creates the links for you from the content editable field, and therefore Autolinker is ignoring them. What you might try doing is removing the IE-generated anchor tags using your browser's DOM before running Autolinker on it. Are you using any libraries? Using jQuery to unwrap the hrefs from the generated tags would make this pretty straightforward. Something like this should do the trick: var // Find all anchor tags within the content, and replace them with just their href's, var autolinkedHtml = Autolinker.link( $contentEl.html() ); — |
Is If $( div_content ).find( 'a' ).each( ... |
Hey, hope you got this solved. Closing this ticket out for now. Feel free to continue to comment though if you have more questions! |
Sorry for the late answer, as it now also works on Safari this is not too high on my priority list anymore :) The part of the code with everything that happens before autolink is being used: var div_inhoud = $("#editedText").html(); //Probleem met html code oplossen: // Find all anchor tags within the content, and replace them with just their href's, //Links op pagina omvormen naar html links: In Chrome, the console gives the error: I really don't know what i'm doing wrong. This is a autolink test on my personal website. Chrome, after applying autolink: jquery.js:2 fb.errorjquery.js:2 fb.tokenizejquery.js:2 fb.selectjquery.js:2 fbjquery.js:2 m.fn.extend.findjquery.js:2 m.fn.initjquery.js:2 mjavascript.js:239 (anonymous function)jquery.js:3 m.event.dispatchjquery.js:3 m.event.add.r.handle
Don't know how to show code in a proper way on GitHub :) But it gives the string with the page content which i'm trying to save to my database. After the page content it gives the errors you can see. |
Ok, so I think I see the problem. You're working with the HTML string rather than the DOM tree structure. I think you want something like this instead: var div_inhoud = $("#editedText"); // note: no call to `.html()` here
// Find all anchor tags within the content, and replace them with just their href's,
// in preparation to be autolinked using Autolinker's settings
div_inhoud.find( 'a' ).each( function( i, elem ) {
$( elem ).replaceWith( elem.href );
} );
// Links op pagina omvormen naar html links:
var htmlToSaveToDatabase = Autolinker.link( div_inhoud.html() );
// Update the HTML of the element on the page with the newly-autolinked HTML
div_inhoud.html( htmlToSaveToDatabase ); I removed the Otherwise, do you have a place where I can see the full code and page that you're editing? That would give me some more context. |
Thanks for this Libary, I really like it!
I tested it in Google Chrome and Firefox, and it worked perfectly.
But Internet Explorer imminently creates a html link when you type one, which makes autolink not do any edits to the links, like opening it on another page and giving it a class.
Safari doesn't auto create a html link, but for some strange reason autolink just ignores links made in safari (with me, at least).
Could you fix, or help me fix, these problems? I really like autolink, would love it if everything worked.
Samuël
The text was updated successfully, but these errors were encountered: