Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Javasript to hide not working in safari
rainbow2011 Offline
Newbie
*

Posts: 1
Joined: Apr 2011
Post: #1
Javasript to hide not working in safari
Hi,
I'm new to the world of safari and iDevices. I'm writing a simple javascript to make some changes to a jsp page when accessed through an ipad and through a normal computer.
My JSP page has 2 DIV elements which I declared as :
Code:
<div id = "notfromIpad"  style="position:absolute">
<div id="fromIpad"  style="position:absolute">

On page load I'm doing this logic to display them one at a time.

<script type="text/javascript">
window.onload=function () {
if ( (navigator.userAgent.indexOf("iPad") != -1)) {
    alert("from ipad");
    document.getElementById('fromIpad').style.visibility="hidden";
   document.getElementById('notFromIpad').style.visibility="visible";
}else{
    alert("not from iPad");
    document.getElementById('notFromIpad').style.visibility="hidden";
     document.getElementById('fromIpad').style.visibility="visible";

}
</script>

This code is working fine in normal browser but not just in safari. In safari, it is displaying both DIVs all the time. Its not hiding one.
Please help.
2011.04.01 02:20 PM
Find all posts by this user Quote this message in a reply
zhenyab Offline
Newbie
*

Posts: 1
Joined: Jun 2011
Post: #2
RE: Javasript to hide not working in safari
Hello!

You have several errors in your script, so how it can work in other browsers - big question:
1. need to close brackets for window.onload function "}"
2. The id attribute must be exact the same all the way including caseSensitivity

Code:
<div id = "notFromIpad"  style="position:absolute"></div>
<div id="fromIpad"  style="position:absolute"></div>

On page load I'm doing this logic to display them one at a time.

<script type="text/javascript">
window.onload=function () {
if ( (navigator.userAgent.indexOf("iPad") != -1)) {
    alert("from ipad");
    document.getElementById('fromIpad').style.visibility="hidden";
   document.getElementById('notFromIpad').style.visibility="visible";
}else{
    alert("not from iPad");
    document.getElementById('notFromIpad').style.visibility="hidden";
     document.getElementById('fromIpad').style.visibility="visible";

}
}
</script>
2011.06.07 11:03 AM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)