admin管理员组文章数量:1335179
Kind of an absurd situation... This is only really only for IE8 and lower.
Anyway I have an iFrame appearing (which I can't control / create an ID for), appreciate it Telerik!
// The only way I can grab it specifically would be:
var iframe = document.frames ? document.frames[id] : document.getElementById(id);
// ^ you grab by ID in IE
var ifWin = iframe.contentWindow || iframe;
But since I don't have the ID, I can't use this method... I've tried a few different methods, with no success.
// tried either window. / or document.
document.frames.print();
window.frames.print();
document.frames[0].print();
I basically just want to just, GRAB the first iFrame -> and print it
Side note: window.print()
works in everything besides IE8 & lower. For IE, it prints only the outer / parent window content, instead of the iFrame that is currently focused on.
Any thoughts?
Update: So somehow doing window.frames[2].print()
in the IE console works (and grabs the correct frame). When I try to put this code in the Javascript, I have the exact same thing: window.frames[2].print()
, IE interprets this code into dot notation window.frames.2
and doesn't work and es back as null or not an object. Typing that same dot notation into the console doesn't work and just gives me "Expected ;" (which makes no sense).
Kind of an absurd situation... This is only really only for IE8 and lower.
Anyway I have an iFrame appearing (which I can't control / create an ID for), appreciate it Telerik!
// The only way I can grab it specifically would be:
var iframe = document.frames ? document.frames[id] : document.getElementById(id);
// ^ you grab by ID in IE
var ifWin = iframe.contentWindow || iframe;
But since I don't have the ID, I can't use this method... I've tried a few different methods, with no success.
// tried either window. / or document.
document.frames.print();
window.frames.print();
document.frames[0].print();
I basically just want to just, GRAB the first iFrame -> and print it
Side note: window.print()
works in everything besides IE8 & lower. For IE, it prints only the outer / parent window content, instead of the iFrame that is currently focused on.
Any thoughts?
Update: So somehow doing window.frames[2].print()
in the IE console works (and grabs the correct frame). When I try to put this code in the Javascript, I have the exact same thing: window.frames[2].print()
, IE interprets this code into dot notation window.frames.2
and doesn't work and es back as null or not an object. Typing that same dot notation into the console doesn't work and just gives me "Expected ;" (which makes no sense).
2 Answers
Reset to default 6Did you try
document.getElementsByTagName('iframe')[0]
I tested this in an IE8 console and it works (but it may still have the problem in your update).
As for the other part of your question about printing the first visible iframe, you probably will want to look at the scrollX and scrollY and the offsetTop and offsetLeft, no?
Most of these old collections in javascript has a method * called item
, so try this:
window.frames.item(2).print();
(*) Do not wonder, typeof window.frames.item
will be 'object'
.
本文标签: javascriptGetting first visible iFrame within a window and printing itStack Overflow
版权声明:本文标题:javascript - Getting first visible iFrame within a window and printing it - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382711a2464412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论