Вопрос

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 comes 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).

Это было полезно?

Решение

Did 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'.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top