1

So I've trying to get Firefox to hide a div on page load without much success. It works in Chrome and IE though. My HTML looks like this

<div id="container">
  <iframe src="www.google.com"></iframe>
</div>

<a href="#" id="showBtn">Show</a>

And my Javascript looks like this

$(document).ready(function () {
  $("#container").dialog({ autoOpen: false, Title: "Hello, World!" });
  $("#container").hide(0);

  $("#showBtn").bind("click", function () {
    $("#container").dialog("open");
  });
});

So here's what I'm trying to do. On page load, the #container would be hidden and remain so until user clicks the 'Show' button.

0x56794E
  • 20,883
  • 13
  • 42
  • 58

5 Answers5

1
<div id="container">
    <iframe src="http://www.google.com"></iframe>
</div>

<a href="#" id="showBtn">Show</a>

jquery code

$('#showBtn').click(function () 
{

  $("#container").css("display","");

});

window.load=$("#container").css("display","none");
K P
  • 392
  • 3
  • 14
0

That works fine in Firefox 19.0 on Mac OS X (as it does in Chrome). Your issue might be with the content you are trying to put in an iframe. It won't work with Google.

Functioning jsfiddle (code is same, included as StackOverflow requires it):

$(document).ready(function () {
  $("#container").dialog({ autoOpen: false, Title: "Hello, World!" });
  $("#container").hide(0);

  $("#showBtn").bind("click", function () {
    $("#container").dialog("open");
  });
});

The reason why Google won't work in an iframe: How to show google.com in an iframe?.

You may find that some versions of jQuery with certain browsers won't work if hide has an invalid parameter of 0.

Community
  • 1
  • 1
Cymen
  • 14,079
  • 4
  • 52
  • 72
0

As @EnterJQ pointed out, hide() without parameter solved the problem!

0x56794E
  • 20,883
  • 13
  • 42
  • 58
0

You can not load google into iframe. see: here

what
  • 338
  • 1
  • 6
  • 13
0

do it in this way

<div id="container" class="display-none">
  <iframe src="www.google.com"></iframe>
</div>

<a href="#" id="showBtn">Show</a>

css

.display-none{
display:none;
}

initially your div would be hidden and when the user clicks show button just toggle the class.

$("#container").toggleClass('display-none');

hope this helps.

ntstha
  • 1,187
  • 4
  • 23
  • 41