+ 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"; }

16th Sep 2017, 2:58 PM
Laith Mohammed Saker
Laith Mohammed Saker - avatar
8 ответов
+ 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
16th Sep 2017, 4:00 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 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.
16th Sep 2017, 3:32 PM
Maz
Maz - avatar
+ 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.
16th Sep 2017, 4:14 PM
Maz
Maz - avatar
+ 7
Disable mark the answer as best that's my very haphazardly answer -_-
16th Sep 2017, 4:44 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 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
16th Sep 2017, 3:41 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 4
@Maz Did you test it on mobile?
17th Sep 2017, 4:07 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 2
i try with browsers not with sololearn. also no result.
16th Sep 2017, 3:43 PM
Laith Mohammed Saker
Laith Mohammed Saker - avatar
+ 1
@Very_Hard thanx
16th Sep 2017, 4:22 PM
Laith Mohammed Saker
Laith Mohammed Saker - avatar