Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML - Hide an iframe

Tags:

html

iframe

How do I hide an iframe, but still load it? Etc. For playing a youtube song.

<iframe src="https://www.youtube.com/embed/X18mUlDddCc?autoplay=1" style="display: none;"></iframe> 

This will hide the iframe, however it dosen't seems to load the iframe. (Song is not playing.)

Thanks

like image 544
user3854743 Avatar asked Aug 21 '14 20:08

user3854743


People also ask

How do I hide an iframe link?

One thing you could try is to obscure it to make it slightly harder for someone to find it. You could have the src attribute be blank and then when the document is ready fetch the URL value from the server in a separate AJAX request and update the iframe tag to include that value in the src .

Can you disable an iframe?

While you can't technically disable HTML iFrames, you can prevent user interaction and make them appear read-only.

Can I hide content inside an iframe from an external domain?

Yes totally doable. Once you assign the parameter to a var, you could then do anything you want… like a hide() on an element. Here is a stack solution.

How do I encrypt an iframe URL?

You can use a generic handler to hide the actually file from location. Now you can/must encrypt also the url parameter to avoid anyone download all your reports. From that you remove all the line that contains the attachment; filename= so the file will be load on the inside of the iframe.


2 Answers

Use can use width: 0; height: 0; position: absolute; and border: 0;

So the updated code will be!

<iframe src="https://www.youtube.com/embed/X18mUlDddCc?autoplay=1" style="position: absolute;width:0;height:0;border:0;"></iframe> 

Added:

style="position: absolute; width:0; height:0; border:0;"

It will hide it, make media to play in the background and it will also collapse it space!

Updated Fiddle

http://jsfiddle.net/ygkvbphs/

like image 71
YOU Avatar answered Sep 20 '22 13:09

YOU


I was still having trouble with the iframe taking up space until I added absolute positioning. Then it stopped taking up space all together.

<iframe src="/auth/sso/" style="width: 0; height: 0; border: 0; border: none; position: absolute;"></iframe>

like image 30
Dan But Avatar answered Sep 21 '22 13:09

Dan But