Dr M L M J
Dr M L M J

Reputation: 2407

How to disable pop-out option in pdf viewer with google doc iframe?

I am using following code to display pdf using google with iframe.. It's working fine. But I want to disable "pop-out" option (which on click opening my pdf in new tab with google docs) shown on right upper corner beside zoomin option on my webpage. Is it possible?

Currently I am using following code -

<iframe src="http://docs.google.com/gview?url=http://example.com/files/myfile.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0">

Upvotes: 12

Views: 14742

Answers (3)

leLabrador
leLabrador

Reputation: 169

Can use sandbox to stop the popup working inside iframe

<iframe 
    sandbox="allow-scripts allow-same-origin"
/>

allow-scripts: to run javascript inside iframe.
allow-same-origin: to allow loading file from google viewer.
without allow-popups, nothing will happen when users click on pop-out icon.

Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe

Upvotes: 10

Pankaj Zade
Pankaj Zade

Reputation: 75

The following solution is useful to remove preview button. Add this code onload function of your iframe. It's applied after iframe is loaded.

var head = $("#iframe").contents().find("head");
var css = '<style type="text/css">' +
          '.ndfHFb-c4YZDc-Wrql6b{display:none}; ' +
          '</style>';
$(head).append(css);

Upvotes: 0

roman m
roman m

Reputation: 26561

Run this javascript (sample with jQuery) on your page (I assume the class is the same for all clients)

$('.ndfHFb-c4YZDc-Wrql6b').remove();

Upvotes: 0

Related Questions