Przykładowa strona wygląda tak:
Kod
<html>
<head>
<title>Strona</title>
</head>
<body>
<p>Hello world</p>
<script type="text/javascript" src="skrypt.js"></script>
</body>
</html>
<head>
<title>Strona</title>
</head>
<body>
<p>Hello world</p>
<script type="text/javascript" src="skrypt.js"></script>
</body>
</html>
Sprawa wygląda tak, że stosowanie jQuery("body").html() albo jQuery("body").clone(true) zwaracają tylko:
Kod
<p>Hello world</p>
Żadne z nich nie zwraca jednak kodu JavaScript. Zrobiłem już nawet coś takiego:
Kod
jQuery("script").each(function() {
jQuery(this).prependTo("html");
} );
jQuery(this).prependTo("html");
} );
Próbowałem już różnych środków, ale jQuery upiera się tylko na kopiowaniu DOM i nie chce za nic mi skopiować JavaScriptu :(. Ma ktoś jakiś pomysł?
EDIT ######################
Dobra, skorzystałem z tego: <a href="http://plugins.jquery.com/project/FullHTML" target="_blank">http://plugins.jquery.com/project/FullHTML</a> i napisałem:
Kod
function getTagHtml(objElement) {
var content = jQuery(objElement).html();
var attribs = jQuery(objElement)[0].attributes;
var tagName = jQuery(objElement)[0].tagName.toLowerCase();
var text = '<'+tagName;
for( var i = 0; i < attribs.length; i++ ) {
var attrName = attribs[i].nodeName;
text += ' ';
text += attrName;
text += '="'
text += $(objElement).attr(attrName);
text += '"';
}
text += '>';
text += content;
text += '</'+tagName+'>';
return text;
}
var content = jQuery(objElement).html();
var attribs = jQuery(objElement)[0].attributes;
var tagName = jQuery(objElement)[0].tagName.toLowerCase();
var text = '<'+tagName;
for( var i = 0; i < attribs.length; i++ ) {
var attrName = attribs[i].nodeName;
text += ' ';
text += attrName;
text += '="'
text += $(objElement).attr(attrName);
text += '"';
}
text += '>';
text += content;
text += '</'+tagName+'>';
return text;
}
Może komuś się przyda :). Taka prowizora, ale działa ;].