Bootstrap Popover - how to add a link to popover text?

I am using Boosttrap 3 Popover.

And now I would like a link to a text popover.

The code:

<a href="#" role="button" class="btn popovers" data-toggle="popover" title="" data-content="test content <a href="" title="test add link">link on content</a>" data-original-title="test title" > test link </a> 

But when I run the code in HTML, I see:

 <a href="#" role="button" class="btn popovers" data-toggle="popover" title="" data-content="test content &lt;a href=" "="">link on content</a> " data-original-title="test title" &gt; test link 

I know this problem in the symbol " but I don’t know, add the link to the link ...

Please tell me how will the correct code be?

PS: if the question already exists, please give me a link.

+49
html hyperlink twitter-bootstrap-3 popover
Nov 30 '13 at 10:42
source share
7 answers

You need to pass the html option with true when initializing the popover, as shown below.

Demo

JS:

 $("[data-toggle=popover]") .popover({html:true}) 

HTML:

 <a href="#" role="button" class="btn popovers" data-toggle="popover" title="" data-content="test content <a href='' title='test add link'>link on content</a>" data-original-title="test title">test link</a> 
+85
Nov 30 '13 at 11:40
source share

Just use the data-html = "true" attribute.

 <button data-toggle="popover" data-content="Link: <a href='xyz.com'>XYZ</a>" data-html="true"> CLICK </button> 
+33
Dec 28 '14 at 23:01
source share

I used data-trigger="focus" and had a problem with the link in the popover content. If you click on the link and hold for a while, the pop-up window disappears and the link "does not work". Some customers complained about this. You can reproduce the problem here .

I used the following code to solve the problem:

data-trigger="manual" in html and

 $("[data-toggle=popover]") .popover({ html: true}) .on("focus", function () { $(this).popover("show"); }).on("focusout", function () { var _this = this; if (!$(".popover:hover").length) { $(this).popover("hide"); } else { $('.popover').mouseleave(function() { $(_this).popover("hide"); $(this).off('mouseleave'); }); } }); 
+4
Mar 26 '18 at 21:31
source share
 <a href="#" class="btn popovers" data-toggle="popover" title="" data-content="test content <a href='' title='test add link'>link on content</a>" data-html="true"><i class="glyphicon glyphicon-info-sign"></i></a> 

Just adding data-html = "true" works with the link :)

+2
May 04 '17 at 7:16
source share

If you want to use focus and link inside the popup, you need to prevent the popup from closing when clicked inside. The cleanest solution I found was to preventDefault clicks on preventDefault in the .popover popup .popover class

 $('body') .on('mousedown', '.popover', function(e) { e.preventDefault() }); }); 
+2
Jan 26 '19 at 14:50
source share

It is worth noting that although the answers given are correct, when using data-trigger="focus" link will cause problems. As I learned from the client, if a click occurs quickly in a pop-up window, the link will work if the user holds the mouse button, then, unfortunately, the trigger fires and a pop-up window appears. So, briefly, consider whether you need a link, and plan for lazy clicks.

+1
Mar 01 '18 at 14:24
source share
 $("body").on("mousedown",".my-popover-content a",function(e){ document.location = e.target.href; }); 

does it for me: basically, take matters into your own hands. Again, this is with the html: true , sanitize: false and trigger: "focus" popover options

0
Jul 10 '19 at 20:09 on
source share



All Articles