+ 3
why no any action when i run the page?
html <p onclick="book()">books</p> <embed src="#" width="40%" height="60%" id="pdf"/> javascript function book() { var x = document.getElementById("pdf"); x.src = "book.pdf"; }
8 Antworten
+ 7
Bc src in embed element is just getter property not setter property
so you can't change destination of embed later like that
(Currently read about it+test+install linux driver)
[Edited]
better use iframe iframe is better than embed.trust me xP
+ 9
I made some tests with your code and (obviously) the main problem is related to the local path, you have to insert a remote path to get a working PDF file in Sololearn.
However, in my case the browser returns an error because "the plug-in is unsupported", i tried to run the code in two different browsers (but always inside the Code Playground) and i got the same error on this code: https://code.sololearn.com/W9nqj7103JY6/?ref=app
Probably there are SL security reasons or... it's just my browser? Anyway, there is a JS library that (perhaps) can help you, take a look here: https://mozilla.github.io/pdf.js/
Note: It seems like PDF.js is not available in CDN yet.
+ 7
@Very_Hard nice one, you can actually be right, however the result is the same here, also by removing and re-adding the element from the DOM, i'm still thinking that an external library can easily do the hard stuff for us, of course with all advantages and disadvantages, an iFrame can gives several issues due to security measures.
+ 7
Disable mark the answer as best
that's my very haphazardly answer -_-
+ 5
ya maz is right
only browsers can support this code of pdf
sololearn is not a browser
btw you may have saw while clicking on the pdf file it don't execute on browser instead it starts downloading
+ 4
@Maz Did you test it on mobile?
+ 2
i try with browsers not with sololearn.
also no result.
+ 1
@Very_Hard
thanx