Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically set popover value with href on rollover in Twitter Bootstrap 3.0

I need to made a popover show an iframe using Twitter Bootstrap 3.0, it popopver should show iframes based on values provided in links using the onmouseover event of href.

I got the first link working but not in 3.0, but in 2.0.2, but the second link is supposed to change the value of the variable and show a different iframe and I don't seem to know how to do it.

$(window).load(function(){
var img = '<iframe frameborder="0" scrolling="no" height="220" width="420"
                  src="http://dxlite.g7vjr.org/?dx=LU5DX&limit=10"></iframe>';
$("#blob").popover({title: 'Last 10 spots for the selected station', content: img});
})  

<a href="#" id="blob" class="btn large primary" rel="popover" style="margin-top:
100px">hover for popover</a>

<a href="#" id="blob" class="btn large primary" rel="popover" onmouseover=""var img =
'<iframe frameborder="0" scrolling="no" height="220" width="420"
src="http://google.com"></iframe>';"" style="margin-top: 100px">hover for popover</a>
like image 986
Martin Avatar asked Oct 15 '13 00:10

Martin


1 Answers

You are overcomplicating i believe.

  • #1 You have duplicate id, you should assign unique id
  • You have syntax errors. See the console.
  • If you need to show bs popover on hover you just need to set the target in the bs popover settings or as a data-attribute.
  • You need to show the iframe as context and not the html text rep of iframe so you need to set data-trigger = "hover" or in the settings.
  • You need to inialte the popover or convert the object to popover by calling the constructor and the reason is stated in the document as below:

For performance reasons, the Tooltip and Popover data-apis are opt in. If you would like to use them just specify a selector option.

  • Demo BS 3
  • Demo BS 2

HTML:

<a href="#" id="blob" class="btn large primary" rel="popover" style="margin-top:
100px">hover for popover</a>

<a href="#" id="blob2" class="btn large primary" data-trigger="hover"  rel="popover" data-html="true" data-content='<iframe frameborder="0" scrolling="no" height="220" width="420"
src="http://dxlite.g7vjr.org/?dx=LU5DX&limit=10"></iframe>' style="margin-top: 100px">hover for popover</a>

JS:

$(window).load(function(){
var img = '<iframe frameborder="0" scrolling="no" height="220" width="420" src="http://dxlite.g7vjr.org/?dx=LU5DX&limit=10"></iframe>';
    $("#blob").popover({title: 'Last 10 spots for the selected station', content: img, html:true});
    $('[rel="popover"]').popover();
})  
like image 139
PSL Avatar answered Oct 18 '22 10:10

PSL