Reputation: 940
I'm using Javascript to load a PDF in an iframe on my web page.
It's not an option to just do:
<iframe id="some" src="some.pdf" ...></iframe>
I really need to add the pdf later using Javascript like:
document.getElementById("some").src = "some.pdf";
My problem is that when the PDF loads it gets the focus for the mouse. I mean, when you try to scroll, instead of having the page scrolling you have a PDF scrolling. This is corrected when I click on another tab and return to the tab with the pdf.
Is there a way to add a PDF using Javascript but disabling the auto focus? Is using an iframe to display PDFs in the page like this even good?
Upvotes: 0
Views: 540
Reputation: 6420
if you want the pdf to be part of a page you have to use iframes. When you don't want it to be focused after load you just listen for the load event and put focus on an other element.
document.getElementById('some').onload= function() {
document.getElementById('otherElement').focus();
};
Upvotes: 1
Reputation: 1514
Force focus on another element on your page after PDF load
var mywhatever = document.getElementById("mywhatever");
mywhatever.focus();
Upvotes: 1