0

I have embedded the content using google doc viewer so am getting cross origin error ,so i have try the following idea

Update

Here is my view.ejs code:

 <div id="viewframe"> 
  <iframe id="viewfile"  name="viewfile" src='https://docs.google.com/viewer?url=<%= urlencode.encode(img) %>&embedded=true' style="width: 100%;height:900px" frameborder="0" scrolling="no" seamless="" allowfullscreen="allowfullscreen">
  </iframe>
 </div>

  <div id="viewframe1"> 
  <iframe id="my-iframe" style="display:none"></iframe>
  </div>

Print button

Print

my app.js

$scope.printdoc=function()
    { 
     var iframe = $('#viewfile').appendTo($('#my-iframe'));
      iframe.on('load', function(){
      iframe.get(0).contentWindow.print();
     });
   }
Vishnu
  • 745
  • 12
  • 32
  • _“If you can get the other domain to return javascript that will do Cross-Domain Communication With Iframes”_ - and, can you …? No clue what you are actually talking about here. And what this has to do with “print” neither. – CBroe Feb 15 '18 at 09:07
  • Thank you for your response, Actually I am displaying the file using google doc viewer. Now i have to take print while am trying to take print am getting cross origin error. So i tried some source in stack overflow and i tried this one. https://stackoverflow.com/questions/48786719/print-functionality-in-angularjs-for-iframe/48787352?noredirect=1#comment84576447_48787352 check this link[ My previous question] – Vishnu Feb 15 '18 at 09:13
  • The Same Origin Policy prevents you from interacting with content loaded into an iframe from a different domain. Any scripting to help overcome that would need to be at least partially implemented by the remote party, and I doubt you can get Google to do that just for you. (Unless they have prepared something in that regard already, but you’d have to check their API docs.) – CBroe Feb 15 '18 at 09:17
  • Content is loading in my viewer , while trying to print am getting this problem . is there any way to overcome this problem – Vishnu Feb 15 '18 at 09:19
  • Yes, you get the problem because you are trying to call a JavaScript method (print) of the iframe window (assuming the problem is the same as in the question you linked to) ... But the approach outlined in the accepted answer to https://stackoverflow.com/questions/38164362/print-a-pdf-via-iframe-cross-domain should help fix this. – CBroe Feb 15 '18 at 09:24
  • I have tried this, but its give blank page, my query is how to pass the PDF url from the container to the proxy – Vishnu Feb 15 '18 at 09:31
  • Try it with static code first, to see if the principle works. How to pass parameters down into an iframe is something you can then do some research on afterwards. – CBroe Feb 15 '18 at 09:38
  • I have tried same code with static , I am getting empty page – Vishnu Feb 15 '18 at 09:52
  • Well then _debug_ what is going on ... And at least edit your question to contain a proper example of your current code; preferably a “live” one so we can directly check. [mcve] – CBroe Feb 15 '18 at 09:53
  • I have updated my question – Vishnu Feb 15 '18 at 10:03
  • You can not just put HTML code into the iframe `src` attribute ... – CBroe Feb 15 '18 at 10:15
  • I have changed now – Vishnu Feb 15 '18 at 10:36
  • Again: [mcve]. Please don’t expect people to set up their own run-able example by copy&pasting your code snippets (and setting up the whole framework around it, which we’d need to do first of all.) Either create a _simple_ example that doesn’t need any extended framework around it, or show something where we can look at this “live”. – CBroe Feb 15 '18 at 10:43
  • Sorry i could not able to provide example live, because it contains aws details and am getting the url from node.. I ll search some other idea.. – Vishnu Feb 15 '18 at 11:07

0 Answers0