vendredi 30 janvier 2015

Bootstrap popover works with html but not requested webpage


I am trying to develop a jquery script which will open a popover containing the webpage when you hover over a table td and close it when you move off of it. So far this is working pretty well . The code I have is:



var html = "";
var $that = "";
var $url = "";

$('td').hover(function() {
var contents = $(this).html();

if (contents.match("^http")) {
console.log('contents', contents);
$that = $(this);
$url = contents;

$.ajax({
type: "POST",
url: "/echo/html/",
context: $that,
data: {u: 'http://ift.tt/gbk8l4'},
dataType: 'html',
error: function(jqXHR, textStatus, errorThrown) {
console.log('error');
console.log(jqXHR, textStatus, errorThrown);
}
}).done(function(html) {
console.log(' here is the html ' + html);


html = '<ul class="nav"><li><a href="#">hola</li><li><a href="#">hola2</li></ul>';
$link = $('<a href="myreference.html" class="p1" data-html="true" data-bind="popover">');
$link.data('content', html);
$(this).html($link);

$that = $(this);

// Trigger the popover to open
$link = $(this).find('a');
$link.popover("show");

})
};
}, function() {
console.log('this2 ', $that);
$link = $that.find('a');
console.log('$link2 ', $link);
$link.popover("hide");
$that.html($url);
});


and you can see it at:


JSFiddle


The problem arises over inserting a webpage into the popover via an ajax request. You can see what happens if you remove the line:



html = '<ul class="nav"><li><a href="#">hola</li><li><a href="#">hola2</li></ul>';


It no longer works. What am I doing wrong and is it possible to load a full webpage into a popover given all the unpredictable js within in?





Aucun commentaire:

Enregistrer un commentaire