Show or Hide IFrame in asp.net page using javascript


In this Code Snippet we are going to see how to show or hide an IFrame content in asp.net web page using javascript code. Here we are showing the IFrame in a div tag. Initially the div tag is not displaying by setting its display property to none. on button click if the div tag is invisible, we are making it visible by setting its display property to block and Visibility property to visible.

In this Code Snippet we are going to see how to show or hide an IFrame content in asp.net web page using javascript code.


<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="var id = document.getElementById('test'); if(id.style.display == 'block'){ id.style.display = 'none'; id.style.visibility = 'hidden';} else{ id.style.display = 'block'; id.style.visibility = 'visible';}" value="Show/Hide" />

<div style="display:none;" id="test" name="test">
<iframe id="test" runat="server" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.EXAMPLE.com%2F&layout=button_count&show_faces=true&width=100&action=recommend&colorscheme=light&;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:100px; height:21px;" allowTransparency="true"></iframe>
</div>
</div>
</form>
</body>


In the above code we are showing the IFrame in a div tag. Initially the div tag is not displayed by setting its display property to none. on button click if the div tag is invisible, we are making it visible by setting its display property to block and Visibility property to visible.
When the IFrame(through div tag) is visible, On button click we are hiding it by setting the display property of the div tag to block.


Article by Vaishali Jain
Miss. Jain Microsoft Certified Technology Specialist in .Net(Windows and Web Based application development)

Follow Vaishali Jain or read 127 articles authored by Vaishali Jain

Comments



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: