Click to See Complete Forum and Search --> : printing multiple iframes
jovialjonny
09-03-2003, 04:09 PM
Hi,
I have a webpage which contains a collection of iframes. I want to let the user print all of the iframes at the click of a button.
So far, by hard coding, I have succeeded in printing a single iframe like so:
function printFrame()
{ document.mainFrame.focus(); //mainFrame is the frame name
document.mainFrame.print();
}
my problem is that I want to loop through all the frame names however IE will only allow the correct frame name, not a variable containing the frame name such as:
var currentFrame = "mainFrame";
document.currentFrame.focus();
document.currentFrame.print();
Does anyone know how I can loop through the iframes and print each one?
AdamBrill
09-03-2003, 04:17 PM
Try this:
framename="mainFrame";
document.frames[framename].print();
jovialjonny
09-03-2003, 05:36 PM
:D Perfect! Thanks a mill!
jovialjonny
09-03-2003, 05:46 PM
Whoops, a little premature there!:rolleyes:
That works fine for any pages on my own domain, but it gives 'acess denied' if I'm printing a webpage from another domain.
Is it possible to print those foreign webpages via a javascript function? I mean I know they could just right click on it and use the context menu (in IE anyway), but can I invoke the same call to print from my own button on my webpage?
Right now this code works fine as long as the pages are on my domain:
function printFrame()
{ var activeFrame = document.getElementById("frm"+activeId);
document.frames[activeFrame.name].focus();
document.frames[activeFrame.name].print();
}
AdamBrill
09-03-2003, 06:19 PM
Do to security issues, you cannot access pages that are not on your domain...
jovialjonny
09-04-2003, 08:45 AM
Originally posted by AdamBrill
Do to security issues, you cannot access pages that are not on your domain...
Ya I know but say there is a foreign webpage in the iframe, if the user right clicks on it and selects print (IE here) it will print fine, I was just wondering if anyone knows a way I can invoke that print call?
Oh and a separate question, when I am looping through the iframes and printing them (this is for my local pages which are working correctly) it brings up the print dialog window for each iframe so the user has to click 'ok' like 3 or 4 times. Does anyone know how I could bundle all these print calls together so the print dialog would only come up once?
Right now the code looks like this:
function printAllFrames()
{ var numTabs = getNumTabs();
for(i=1; i<= numTabs; i++)
{ var currentFrame = document.getElementById("frm"+i);
document.frames[currentFrame.name].focus();
document.frames[currentFrame.name].print();
}
}
Any suggestions appreciated thanks!:)