0

So I have a iFrame that is linked to a out sourced quote on another website. Is it possible to add a print button for the results inside that iFrame?

I have the following code attempt but it's not doing much at all - When the button is clicked, it does nothing

<iframe src="https://www.compulife.net/website/1295/quoter.html" width="750 pixels" id="test" name="test" height="750 pixels" frameborder="0" formtarget="_blank"></iframe>

<input type="button" value="Print" onclick="test()" />

<script>
function test {
window.frames["test"].focus();
window.frames["test"].print();
}
</script>

Error:

Uncaught TypeError: test is not a function
    at HTMLInputElement.onclick

Is there something that I might be doing wrong?

enter image description here

SLE
  • 690
  • 1
  • 11

1 Answers1

1

I think there are two mistakes you are doing the typo error for your function instead of

test() you have called just test and secondly

Uncaught TypeError: test is not a function at HTMLInputElement.onclick

is from the window.frames["test"].print(); instead of this you can use

document.getElementById("test").contentWindow.print();

Even if you managed to clear al this error since you mentioned I have an iFrame that is linked to an outsourced quote on another website won't get the result because

you are going to end up in an error like this

SecurityError: Blocked a frame with origin from accessing a cross-origin frame

This is because You can't access an iframe with different origin using JavaScript, it would be a huge security flaw if you could do it.

see the workaround at:SecurityError: Blocked a frame with origin from accessing a cross-origin frame

marcelo
  • 433
  • 3
  • 14