jQuery append() 到新窗口中不适用于 Microsoft Edge [英] jQuery append() into new window not working with Microsoft Edge
问题描述
Microsoft Edge 在尝试将克隆的内容附加到新窗口时抛出不支持此类接口"错误.下面是一个例子:
jQuery(document).ready(function() {jQuery('.trigger').click(function() {var target = jQuery(this).data('print_target');var w = window.open('', '', 'status=no, toolbar=no, menubar=no, location=no');var print_html = ''+ document.getElementsByTagName('title')[0].innerHTML + '</title></head><body></body></html>';w.document.write(print_html);var ua = window.navigator.userAgent;var ie = true;//.html() 需要 IE 浏览器如果(ua.indexOf(MSIE")!= -1){//console.log('MSIE - Craptastic');jQuery(w.document.body).append(jQuery(target).clone(true).html());}否则如果(ua.indexOf(三叉戟/")!= -1){//console.log('IE 11 - 三叉戟');jQuery(w.document.body).append(jQuery(target).clone(true).html());}否则如果(ua.indexOf(边缘/")!= -1){console.log('IE 12 - Edge');//错误:不支持这样的接口jQuery(w.document.body).append(jQuery(target).clone(true).html());//作品//jQuery(w.document.body).append('嘿伙计,这是一些文本');//作品//jQuery(w.document.body).html( jQuery( target ).clone( true ).html() );}别的{//console.log('正确的浏览器');jQuery(w.document.body).append(jQuery(target).clone(true));即=假;}});});
这只是 Microsoft Edge 的一个问题,它适用于所有基于标准的浏览器和 IE 浏览器 7、8、9、10 和 11.一个类似的问题是 在此线程中提出 但没有解决.
这里是一个 jsfiddle,显示了什么:https://jsfiddle.net/switzerbaden/nhtywLsp/
先克隆 HTML,然后在之前添加 div 并在之后关闭它:
var new_target = jQuery.trim( jQuery( target ).clone( true ).html() );jQuery( w.document.body ).append( "" + new_target + "" );
Microsoft Edge is throwing 'No such interface supported' error when trying to append cloned content into new window. Here is an example:
jQuery(document).ready(function() {
jQuery('.trigger').click(function() {
var target = jQuery(this).data('print_target');
var w = window.open('', '', 'status=no, toolbar=no, menubar=no, location=no');
var print_html = '<!DOCTYPE html><head><title>' + document.getElementsByTagName('title')[0].innerHTML + '</title></head><body></body></html>';
w.document.write( print_html );
var ua = window.navigator.userAgent;
var ie = true;
//.html() required for IE browsers
if ( ua.indexOf("MSIE ") != -1) {
//console.log('MSIE - Craptastic');
jQuery(w.document.body).append( jQuery( target ).clone( true ).html() );
}
else if ( ua.indexOf("Trident/") != -1) {
//console.log('IE 11 - Trident');
jQuery(w.document.body).append( jQuery( target ).clone( true ).html() );
}
else if ( ua.indexOf("Edge/") != -1 ){
console.log('IE 12 - Edge');
//error: No such interface supported
jQuery(w.document.body).append( jQuery( target ).clone( true ).html() );
//works
//jQuery(w.document.body).append( 'hey dude, this is some text' );
//works
//jQuery(w.document.body).html( jQuery( target ).clone( true ).html() );
}
else{
//console.log('proper browser');
jQuery(w.document.body).append( jQuery( target ).clone( true ) );
ie = false;
}
});
});
This is only an issue with Microsoft Edge, it works in all standards based browsers and IE browsers 7,8,9,10 and 11. A similar issue has been raised in this thread but not resolved.
here is a jsfiddle showing what's what: https://jsfiddle.net/switzerbaden/nhtywLsp/
First clone the HTML, then add div before and close it after:
var new_target = jQuery.trim( jQuery( target ).clone( true ).html() );
jQuery( w.document.body ).append( "<div>" + new_target + "</div>" );
这篇关于jQuery append() 到新窗口中不适用于 Microsoft Edge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!