此解决方案在Firefox 3.0+中运行良好,但IE8/7只是打印整个页面,而不是特定的iframe.
这是单击打印链接时调用的函数:
var printfunc= function(){
var url = http://someurl.aspx;
//This iFrame has style="visibility: hidden; position: absolute; left: -9000px;"
var printIFrame = GetObj('PrintIFrame');
printIFrame.src = url;
}
Run Code Online (Sandbox Code Playgroud)
加载到隐藏iframe中的aspx调用onload事件处理程序上的print函数:
<body onload="PrintJS.Print();">
Run Code Online (Sandbox Code Playgroud)
打印功能:
this.Print = function(){
self.focus();
self.print();
return false;
}
Run Code Online (Sandbox Code Playgroud)
我也尝试用"窗口"代替"自我".两种解决方案在FF中运行良好,但IE似乎没有得到正确的范围.有什么想法吗?跨浏览器解决方案会很棒!另外,我宁愿使用CSS打印样式,但我打印的内容与页面上的内容不同,因此需要将html加载到隐藏的iframe中.
在研究IE的JavaScript条件评论时,我偶然发现了@cc_on.这似乎有效.但是,条件注释的维基百科条目为更强大的IE检测提供了以下代码,特别是IE6:
/*@cc_on
@if (@_jscript_version > 5.7)
document.write("You are using IE8+");
@elif (@_jscript_version == 5.7 && window.XMLHttpRequest)
document.write("You are using IE7");
@elif (@_jscript_version == 5.6 || (@_jscript_version == 5.7 && !window.XMLHttpRequest))
document.write("You are using IE6");
@elif (@_jscript_version == 5.5)
document.write("You are using IE5.5");
@else
document.write("You are using IE5 or older");
@end
@*/
Run Code Online (Sandbox Code Playgroud)
问题是,我得到一个"预期的常量"javascript错误!window.XMLHttpRequest.
很明显,维基百科需要一些帮助,我需要让它发挥作用.谁能帮我吗?
javascript internet-explorer conditional-comments internet-explorer-6 browser-feature-detection
我目前使用Textmate进行大部分编辑,但是我正在学习Java课程并且想知道是否有更好的编辑器,特别是那些可能具有某种形式的智能感知或主动调试的编辑器.