How to disable pdf toolbar download button in iframe - javascript

I have a web service which will return pdf stream for a given document id and I will set the content type to application/pdf and write the out put to IFRAME upto this point I am done and OK!
My problem is :
My requirement is to disable the pdf download toolbar button in IFRAME, is there any way using JavaScript or j query to disable the PDF toolbar buttons,
i tried some thing like this:
<iframe src="view/1.pdf?page=hsn#toolbar=0" width="875" height="95%" id="iframe11">
<p>Your browser does not support iframes.</p>
</iframe>
I tried setting toolbar=0 for iframe tag but it dint work.
an anyone please tell me how to achieve this ?

I hope I am not very late to reply. But here's is something you can do to prevent the users. Use iFrame to display your PDF and make sure that you are displaying using Google. I used the following code :
<iframe src="http://docs.google.com/gview?url=http://www.tutorialspoint.com/php/php_tutorial.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0">
</iframe>
Here you can simply change the url=http://www.tutorialspoint.com/php/php_tutorial.pdf and replace it by your own URL where you kept your PDF.

Use embed tag instead iframe tag:
<embed src="http://localhost/yourpdf.pdf#toolbar=0" style="width:600px; height:500px;">

Related

Prevent an iFrame from redirecting to a url other than the src url

I have an iFrame that displays a 3rd party eform for our customers to fill out. After the form is submitted, the iframe displays another page that I would like to prevent from showing. I've tried using the sandbox attribute to accomplish this but it doesn't seem to have any effect.
<iframe src="form-url"
width="100%" height="1200px" scrolling="no" sandbox="allow-forms allow-scripts"></iframe>
In HTML5 you can use sandbox property. Please see Pankrat's answer below. http://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/

how to print iframe google docs viewer open document

I am using google docs viewer for show my uploaded document and i want to print it, but i can't print those document using jQuery.
I want to print iframe document but it is not by my code. how to print that document??
<button id="printbtn" onclick="myFunction()">Print</button>
<iframe src="http://docs.google.com/viewer?url=<?php echo urlencode(UPLOAD_URL.$file_name); ?>&embedded=true" frameborder="0" scrolling="no" id="iframe" style="border: none;" width="800" height="470"></iframe>
<script>
function myFunction(){
window.frames["iframe"].focus();
window.frames["iframe"].print(); // NOT WORKING
}
</script>
Please help me......
I did some digging, found its not possible,
because docs.google is going to be a different domain from yours.
I tried this,
document.querySelector('iframe').contentWindow.print()
and got 'Blocked a frame with origin "http://mydomain" from accessing a cross-origin frame.'.
Lets say, even if google allowed cross domain, the print function wont work. because google docs viewer opens another window for printing.
I've reached a conclusion that google devs have smartly made this not possible.

Refused to display a website in a frame because of its 'X-Frame-Options'

I'm trying to display Facebook page in an simple HTML page which only contains an iframe.
Here's my HTML code:
<html>
<body>
<iframe src="http://www.facebook.com"></iframe>
</body>
</html>
I'm always getting this error in Google Chrome's console:
Refused to display 'http://www.facebook.com/' in a frame because it
set 'X-Frame-Options' to 'DENY'.
BTW, I'm having this problem also with these iframes:
<iframe src="https://mail.google.com/mail/mu/mp/any"></iframe>
<iframe src="http://m.facebook.com"></iframe>
<iframe src="http://m.youtube.com"></iframe>
<iframe src="http://m.dropbox.com"></iframe>
<iframe src="http://m.yahoo.com"></iframe>
<iframe src="http://www.google.com"></iframe>
<iframe src="http://mail.google.com"></iframe>
<iframe src="http://www.facebook.com"></iframe>
<iframe src="http://www.youtube.com"></iframe>
<iframe src="http://www.dropbox.com"></iframe>
<iframe src="http://www.yahoo.com"></iframe>
Meanwhile, this iframe is working well !
<iframe src="http://www.google.com/custom"></iframe>
How to solve this ?
EDIT based on comments: Is there an alternative of using iframe if this is unsolvable ? Something like browser tag in XUL ? I already tried browser tag in Firefox extension and it works well, but I'm now coding a chrome extension, so I cannot depend on XUL anymore ?
Yes, you could
use server-side includes, to fetch it from the server and include it in an iframe
use a custom browser which does not recognize that header
complicated: use websockets to create your own Javascript HTTP client, fetch the page, and insert it into the DOM
For those who are interested, this cannot be done !

Javascript in Iframe within Div not working

I have a webpage that I would like to embed within another page. On the page that is to be embedded I have some window.onload javascript that will load a PDF document via the embed tag. If I use just the Iframe tag like this:
<iframe name="content" id="iframe" allowtransparency="true" src="Pages/menu.html" scrolling="no"></iframe>
The Javascript will run just fine. But I am trying to create a background and border for the iframe so I have wrapped the iframe in a div like so:
<div id="content" class="border">
<iframe name="content" id="iframe" allowtransparency="true" src="Pages/menu.html" scrolling="no"></iframe>
</div>
As soon as I do it this way the javascript will not run. Here is the screenshot of what I am trying to do. I do not believe that the styling that is present on the div ( curved borders, gradient, etc is possible on an iframe)
I am using PDFObject to generate the PDF on the page. The iframe is also loading the company's external website in the content section on demand and this is what they want so unfortunately i have to use iframes. This has to be done without using anything except javascript as well otherwise I would just use php.
I have to post the SCREENSHOT outside of this site on photobucket due to restritions sorry:
http://i721.photobucket.com/albums/ww217/the_t3rminat0r/Capture-2.png
It looks margin property in div style (or border class in your example) causes the problem.

How to refresh/reload embed of application/pdf?

I have an embed code using application/pdf to show a pdf document on the page.
I used javascript to change the src attribute of the embed, which a link is clicked. then confimed using alerts to see that the src did change.
but the same pdf is still showing on the page.
How do I refresh/reload the embed tag (not the whole page)? I think this will fix it.
How do you embed the PDF? If you are using an iframe, you can use the reload method.
<iframe id="myIframe" src="your.pdf" height="200" width="200"></iframe>
<script language="javascript" type="text/javascript">
getElementById('myIframe').contentDocument.location.reload()
</script>
You can also append a random string (like the current timestamp) as a GET parameter to the PDF URL to make sure the browser doesn't use its cache.

Categories

Resources