Javascript in safari
Problem is that my script will work perfectly in safari if I target a table, an object tag, an embed tag, or it seems like anything but a div. Actually there is a whole subset of questions with regards to this. For example, you will notice some redundant sode in my script, the reason being that for some reason, safari is "losing track" of the variables that I declare in the begining of the script. I recognize this is most likely my fault, but I'm really curious as to how I can make this better.
Keep in mind that I'm a relative neophyte to the javascript world. Here are the details.
This is a snippet from my .JS file
<code>
function changeWide(myID, myWide, pxVal){
var win_width = window.innerWidth;
var table = document.getElementById("myID");
if (pxVal != null) {
//var table = document.getElementById("tableMain");
document.getElementById(myID).setAttribute("width",pxVal);
document.getElementById('extraD').innerHTML=('target = ' + myID + ' Window = ' + win_width + ' pxVal = ' + pxVal + ' var table =' + table);
}
else {
if (win_width < myWide) {
document.getElementById(myID).setAttribute("width", myWide);
document.getElementById('extraD').innerHTML=('target = ' + myID + ' Window = ' + win_width + ' My Width set to = ' + myWide);
}
else {
document.getElementById(myID).setAttribute("width", '100%');
document.getElementById('extraD').innerHTML=('target = ' + myID + ' Window = ' + win_width + ' My Width set to = ' + myWide);
}
}
}
</code>
Here is a dummed down version of my html:
[noparse]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>sizer 3</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background: #241A0D url(../graphics/pattern.gif);
}
.tester2 {
margin-left: auto;
margin-right: auto;
height: 200px;
width: 400px;
background: #ffffff;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #493825;
text-align: center;
}
.tester {
margin-left: auto;
margin-right: auto;
height: 40px;
width: 400px;
background: #241A0D;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #493825;
text-align: center;
}
-->
</style>
<script type="text/javascript" src="../scripts/width.js"></script>
</head>
<body onResize="changeWide('mainMovie', 830, null);" onLoad="changeWide('mainMovie', 830, null);">
this is the div area that should resize
this is the div id 'extraD' to see if the code is working
<button onclick="changeWide('mainMovie', 820, '50%');">50%</button>
<button onclick="changeWide('mainMovie', 820, 200);">200px</button>
<button onclick="changeWide('mainMovie', 820, 400);">400px</button>
<button onclick="changeWide('mainMovie', 820, '100%');">100%</button>
</body>
[/noparse]
Only pretend that you can see my div tags, cause I don't know how to make them visible in this forum, sorry 😟
thanks much
G5 Mac OS X (10.4.6)