Enrique Benitez
Enrique Benitez

Reputation: 679

Iframe PDF Change page on click url

I want to go between pages inside a PDF File contained in a IFRAME by just clicking on a link.

This is what i made so far:

HTML:

<a href="#" onclick="return pagina(10);">Pagina 10</a>
<iframe name="ifrx" id="ifrx" src="1430263377Physic.pdf" style="height:800px; width:1170px">

Script:

<script>
    function pagina(pag) {
        $("#ifrx").attr('src','').delay(100).attr('src','1430263377Physic.pdf#page='+pag);
        return false;
    }
</script>

But doesn't work, im trying to achieve this but with no luck.

Upvotes: 4

Views: 4423

Answers (1)

Eryk Napierała
Eryk Napierała

Reputation: 506

Change attr to prop. Like that:

function pagina(pag) {
    $("#ifrx").prop('src','1430263377Physic.pdf#page='+pag);

    return false;
}

Attribute is used to set initial value of iframe object property when parsing, but when you're changing the attribute, value doesn't populate to property.

By the way, as far as I know, there is no need to clear src, wait and set it to right value.

UPDATE:

I checked this approach for websites (see here). I guess it's impossible for PDFs, so replacing iframe with new one, with updated src can be only possible way to do it.

Upvotes: 1

Related Questions