Link to home
Start Free TrialLog in
Avatar of duncanb7
duncanb7

asked on

Body align to second frame in javascript

Dear Expert,
I try to set two frame in my webpage, first frame is input box webpage and second frame is
re-direct URL web page based on the input product NO in the input box in the first frame
We call second frame wiht its  id="Frame1"
I get two questions, hopeyou can hlep
Question-1 I would like to know how to change second iframe's body margin that will align to most top,left, right,
botton to its frame(I mean second frame), I try my code but it is failed, please view the code
 I use Html-DOM   to acces second frame body, but it fail like
document.getElementById("frame1").document.body.style.marginTop='0';
document.getElementById("frame1").document.body.style.marginLeft='0';


Question-2,  Since the second frame will redirect to Excel's htm webpage
and its htm name is based on the product No in the input box, I could not get rid of the scroll bar
of the second frame even I try  two way to fix this but fail. How to combine both
frame's scroll  bar as one ?
1- <iframe height="700" marigin="0" width="1400" scrolling="no"  border="0px" id="frame1" src="http://www.website.com/index.htm">
scrolling="NO" is not response at all
2_ ANd try this document.getElementById("frame1").document.body.style.overflow='hidden';
that is also no any response
Please view my image you will know my question2

 It seems I do anything that is no any response , Please advise
Duncan
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<style type="text/css">
* {
font-size:15px;
font-family:Tahoma, Arial, 'Trebuchet MS', Verdana;
}

html,body {
background-color: #4169e1 ;
margin:1px;
padding:0;
height:100%;

}

</style>
<script type="text/javascript">

// e - event, el - element, fn- callback function
function checkEnter(e, el,fn) {
    var key=e.keyCode || e.which;
    if (key==13){
       fn();
el.value='';
document.getElementById("frame1").document.body.style.overflow='hidden';
document.getElementById("frame1").document.body.style.marginTop='0';
document.getElementById("frame1").document.body.style.marginLeft='0';
document.getElementById("frame1").document.body.style.marginBottom='0';
document.getElementById("frame1").document.body.style.marginRight='0';
return false;
    }
    return true;
}

function formSubmit() {

  var my_val = document.getElementById('text1').value;
  // check if value is empty
  if ( my_val.length > 0) { 
    document.getElementById("frame1").src="http://www.mywebiste.com/"+ my_val +".htm";
 
  }

}


</script>
</HEAD>
<body>

<input  style="width: 100px; height: 20px;font-size:16pt;" size="12" type="text" name="text1" id="text1" value=0 onclick="this.value=''; this.className='highlighted'" 
    onblur="if(this.value=='')this.value=this.defaultValue; this.className=''"
onkeydown="return checkEnter(event, this,formSubmit);"  >

<input type="button"  value="submit" onclick="formSubmit();" />

<iframe height="700" marigin="0" width="1400" scrolling="no"  border="0px" id="frame1" src="http://www.website.com/index.htm">
</body>
</HTML>

Open in new window

Snap16.jpg
Snap20.jpg
Avatar of wmadrid1
wmadrid1
Flag of Colombia image

Hi,
1.
document.getElementById("frame1").contentWindow.document.body.style.marginTop='0';
document.getElementById("frame1").contentWindow.document.body.style.marginLeft='0';

2.
Try
overflow:auto
Avatar of duncanb7
duncanb7

ASKER

Thanks for your reply at least,
Display result  is same as before  for 1 & 2
At 2, I try =
document.getElementById("frame1").contentWindow.document.body.style:auto  ' failed, same as before
document.getElementById("frame1").contentWindow.document.body.style='auto'  ' failed same as before
document.getElementById("frame1").document.body.style:auto  ' failed , same as before
document.getElementById("frame1").document.body.style='auto'  ' failed, same as before
So you will see why scroll="0" is not working in <iframe height="700" marigin="0" width="1400" scrolling="no"  border="0px" id="frame1" src="http://www.website.com/index.htm">

So I go directly to 1000.htm page that is generated by Excel saveas htm file, I know ther is frameset inside( please also
view part of 1000.htm code attached in code area"), You can find frameset, and if  I put scrolling=no in this
"<frame src=\""+document.all.item("shLink")[0].href+"\" name=\"frSheet\"  noresize >"+ ,,, scroll bar is gone and no show
WHy ?


function fnBuildFrameset()
{
 var szHTML="<frameset rows=\"*,18\" border=0 width=0 frameborder=no framespacing=0>"+
  "<frame src=\""+document.all.item("shLink")[0].href+"\" name=\"frSheet\"  noresize >"+
  "<frameset cols=\"54,*\" border=0 width=0 frameborder=no framespacing=0>"+
  "<frame src=\"\" name=\"frScroll\" marginwidth=0 marginheight=0 scrolling=no>"+
  "<frame src=\"\" name=\"frTabs\" marginwidth=0 marginheight=0 scrolling=no>"+
  "</frameset></frameset><plaintext>";





<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta name="Excel Workbook Frameset">
<meta http-equiv=Content-Type content="text/html; charset=big5">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="1000.files/filelist.xml">
<link rel=Edit-Time-Data href="1000.files/editdata.mso">
<link rel=OLE-Object-Data href="1000.files/oledata.mso">
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>kkw</o:Author>
  <o:LastAuthor>kkw</o:LastAuthor>
  <o:Created>2010-11-06T19:15:01Z</o:Created>
  <o:LastSaved>2010-11-12T18:45:49Z</o:LastSaved>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
 <o:OfficeDocumentSettings>
  <o:Colors>
   <o:Color>
    <o:Index>14</o:Index>
    <o:RGB>#DDDDDD</o:RGB>
   </o:Color>
  </o:Colors>
 </o:OfficeDocumentSettings>
</xml><![endif]--><![if !supportTabStrip]>
<link id="shLink" href="1000.files/sheet001.htm">
<link id="shLink" href="1000.files/sheet002.htm">

<link id="shLink">

<script language="JavaScript">
<!--
 var c_lTabs=2;

 var c_rgszSh=new Array(c_lTabs);
 c_rgszSh[0] = "Daily13";
 c_rgszSh[1] = "Intra13";



 var c_rgszClr=new Array(8);
 c_rgszClr[0]="window";
 c_rgszClr[1]="buttonface";
 c_rgszClr[2]="windowframe";
 c_rgszClr[3]="windowtext";
 c_rgszClr[4]="threedlightshadow";
 c_rgszClr[5]="threedhighlight";
 c_rgszClr[6]="threeddarkshadow";
 c_rgszClr[7]="threedshadow";

 var g_iShCur;
 var g_rglTabX=new Array(c_lTabs);

function fnGetIEVer()
{
 var ua=window.navigator.userAgent
 var msie=ua.indexOf("MSIE")
 if (msie>0 && window.navigator.platform=="Win32")
  return parseInt(ua.substring(msie+5,ua.indexOf(".", msie)));
 else
  return 0;
}

function fnBuildFrameset()
{
 var szHTML="<frameset rows=\"*,18\" border=0 width=0 frameborder=no framespacing=0>"+
  "<frame src=\""+document.all.item("shLink")[0].href+"\" name=\"frSheet\"  noresize >"+
  "<frameset cols=\"54,*\" border=0 width=0 frameborder=no framespacing=0>"+
  "<frame src=\"\" name=\"frScroll\" marginwidth=0 marginheight=0 scrolling=no>"+
  "<frame src=\"\" name=\"frTabs\" marginwidth=0 marginheight=0 scrolling=no>"+
  "</frameset></frameset><plaintext>";

 with (document) {
  open("text/html","replace");
  write(szHTML);
  close();
 }

 fnBuildTabStrip();
}

function fnBuildTabStrip()
{
 var szHTML=
  "<html><head><style>.clScroll {font:8pt Courier New;color:"+c_rgszClr[6]+";cursor:default;line-height:10pt;}"+
  ".clScroll2 {font:10pt Arial;color:"+c_rgszClr[6]+";cursor:default;line-height:11pt;}</style></head>"+
  "<body onclick=\"event.returnValue=false;\" ondragstart=\"event.returnValue=false;\" onselectstart=\"event.returnValue=false;\" bgcolor="+c_rgszClr[4]+" topmargin=0 leftmargin=0><table cellpadding=0 cellspacing=0 width=100%>"+
  "<tr><td colspan=6 height=1 bgcolor="+c_rgszClr[2]+"></td></tr>"+
  "<tr><td style=\"font:1pt\">&nbsp;<td>"+
  "<td valign=top id=tdScroll class=\"clScroll\" onclick=\"parent.fnFastScrollTabs(0);\" onmouseover=\"parent.fnMouseOverScroll(0);\" onmouseout=\"parent.fnMouseOutScroll(0);\"><a>&#171;</a></td>"+
  "<td valign=top id=tdScroll class=\"clScroll2\" onclick=\"parent.fnScrollTabs(0);\" ondblclick=\"parent.fnScrollTabs(0);\" onmouseover=\"parent.fnMouseOverScroll(1);\" onmouseout=\"parent.fnMouseOutScroll(1);\"><a>&lt</a></td>"+
  "<td valign=top id=tdScroll class=\"clScroll2\" onclick=\"parent.fnScrollTabs(1);\" ondblclick=\"parent.fnScrollTabs(1);\" onmouseover=\"parent.fnMouseOverScroll(2);\" onmouseout=\"parent.fnMouseOutScroll(2);\"><a>&gt</a></td>"+
  "<td valign=top id=tdScroll class=\"clScroll\" onclick=\"parent.fnFastScrollTabs(1);\" onmouseover=\"parent.fnMouseOverScroll(3);\" onmouseout=\"parent.fnMouseOutScroll(3);\"><a>&#187;</a></td>"+
  "<td style=\"font:1pt\">&nbsp;<td></tr></table></body></html>";

 with (frames['frScroll'].document) {
  open("text/html","replace");
  write(szHTML);
  close();
 }

 szHTML =
  "<html><head>"+
  "<style>A:link,A:visited,A:active {text-decoration:none;"+"color:"+c_rgszClr[3]+";}"+
  ".clTab {cursor:hand;background:"+c_rgszClr[1]+";font:9pt ¿¿¿¿;padding-left:3px;padding-right:3px;text-align:center;}"+
  ".clBorder {background:"+c_rgszClr[2]+";font:1pt;}"+
  "</style></head><body onload=\"parent.fnInit();\" onselectstart=\"event.returnValue=false;\" ondragstart=\"event.returnValue=false;\" bgcolor="+c_rgszClr[4]+
  " topmargin=0 leftmargin=0><table id=tbTabs cellpadding=0 cellspacing=0>";

 var iCellCount=(c_lTabs+1)*2;

 var i;
 for (i=0;i<iCellCount;i+=2)
  szHTML+="<col width=1><col>";

 var iRow;
 for (iRow=0;iRow<6;iRow++) {

  szHTML+="<tr>";

  if (iRow==5)
   szHTML+="<td colspan="+iCellCount+"></td>";
  else {
   if (iRow==0) {
    for(i=0;i<iCellCount;i++)
     szHTML+="<td height=1 class=\"clBorder\"></td>";
   } else if (iRow==1) {
    for(i=0;i<c_lTabs;i++) {
     szHTML+="<td height=1 nowrap class=\"clBorder\">&nbsp;</td>";
     szHTML+=
      "<td id=tdTab height=1 nowrap class=\"clTab\" onmouseover=\"parent.fnMouseOverTab("+i+");\" onmouseout=\"parent.fnMouseOutTab("+i+");\">"+
      "<a href=\""+document.all.item("shLink")[i].href+"\" target=\"frSheet\" id=aTab>&nbsp;"+c_rgszSh[i]+"&nbsp;</a></td>";
    }
    szHTML+="<td id=tdTab height=1 nowrap class=\"clBorder\"><a id=aTab>&nbsp;</a></td><td width=100%></td>";
   } else if (iRow==2) {
    for (i=0;i<c_lTabs;i++)
     szHTML+="<td height=1></td><td height=1 class=\"clBorder\"></td>";
    szHTML+="<td height=1></td><td height=1></td>";
   } else if (iRow==3) {
    for (i=0;i<iCellCount;i++)
     szHTML+="<td height=1></td>";
   } else if (iRow==4) {
    for (i=0;i<c_lTabs;i++)
     szHTML+="<td height=1 width=1></td><td height=1></td>";
    szHTML+="<td height=1 width=1></td><td></td>";
   }
  }
  szHTML+="</tr>";
 }

 szHTML+="</table></body></html>";
 with (frames['frTabs'].document) {
  open("text/html","replace");
  charset=document.charset;
  write(szHTML);
  close();
 }
}

function fnInit()
{
 g_rglTabX[0]=0;
 var i;
 for (i=1;i<=c_lTabs;i++)
  with (frames['frTabs'].document.all.tbTabs.rows[1].cells[fnTabToCol(i-1)])
   g_rglTabX[i]=offsetLeft+offsetWidth-6;
}

function fnTabToCol(iTab)
{
 return 2*iTab+1;
}

function fnNextTab(fDir)
{
 var iNextTab=-1;
 var i;

 with (frames['frTabs'].document.body) {
  if (fDir==0) {
   if (scrollLeft>0) {
    for (i=0;i<c_lTabs&&g_rglTabX[i]<scrollLeft;i++);
    if (i<c_lTabs)
     iNextTab=i-1;
   }
  } else {
   if (g_rglTabX[c_lTabs]+6>offsetWidth+scrollLeft) {
    for (i=0;i<c_lTabs&&g_rglTabX[i]<=scrollLeft;i++);
    if (i<c_lTabs)
     iNextTab=i;
   }
  }
 }
 return iNextTab;
}

function fnScrollTabs(fDir)
{
 var iNextTab=fnNextTab(fDir);

 if (iNextTab>=0) {
  frames['frTabs'].scroll(g_rglTabX[iNextTab],0);
  return true;
 } else
  return false;
}

function fnFastScrollTabs(fDir)
{
 if (c_lTabs>16)
  frames['frTabs'].scroll(g_rglTabX[fDir?c_lTabs-1:0],0);
 else
  if (fnScrollTabs(fDir)>0) window.setTimeout("fnFastScrollTabs("+fDir+");",5);
}

function fnSetTabProps(iTab,fActive)
{
 var iCol=fnTabToCol(iTab);
 var i;

 if (iTab>=0) {
  with (frames['frTabs'].document.all) {
   with (tbTabs) {
    for (i=0;i<=4;i++) {
     with (rows[i]) {
      if (i==0)
       cells[iCol].style.background=c_rgszClr[fActive?0:2];
      else if (i>0 && i<4) {
       if (fActive) {
        cells[iCol-1].style.background=c_rgszClr[2];
        cells[iCol].style.background=c_rgszClr[0];
        cells[iCol+1].style.background=c_rgszClr[2];
       } else {
        if (i==1) {
         cells[iCol-1].style.background=c_rgszClr[2];
         cells[iCol].style.background=c_rgszClr[1];
         cells[iCol+1].style.background=c_rgszClr[2];
        } else {
         cells[iCol-1].style.background=c_rgszClr[4];
         cells[iCol].style.background=c_rgszClr[(i==2)?2:4];
         cells[iCol+1].style.background=c_rgszClr[4];
        }
       }
      } else
       cells[iCol].style.background=c_rgszClr[fActive?2:4];
     }
    }
   }
   with (aTab[iTab].style) {
    cursor=(fActive?"default":"hand");
    color=c_rgszClr[3];
   }
  }
 }
}

function fnMouseOverScroll(iCtl)
{
 frames['frScroll'].document.all.tdScroll[iCtl].style.color=c_rgszClr[7];
}

function fnMouseOutScroll(iCtl)
{
 frames['frScroll'].document.all.tdScroll[iCtl].style.color=c_rgszClr[6];
}

function fnMouseOverTab(iTab)
{
 if (iTab!=g_iShCur) {
  var iCol=fnTabToCol(iTab);
  with (frames['frTabs'].document.all) {
   tdTab[iTab].style.background=c_rgszClr[5];
  }
 }
}

function fnMouseOutTab(iTab)
{
 if (iTab>=0) {
  var elFrom=frames['frTabs'].event.srcElement;
  var elTo=frames['frTabs'].event.toElement;

  if ((!elTo) ||
   (elFrom.tagName==elTo.tagName) ||
   (elTo.tagName=="A" && elTo.parentElement!=elFrom) ||
   (elFrom.tagName=="A" && elFrom.parentElement!=elTo)) {

   if (iTab!=g_iShCur) {
    with (frames['frTabs'].document.all) {
     tdTab[iTab].style.background=c_rgszClr[1];
    }
   }
  }
 }
}

function fnSetActiveSheet(iSh)
{
 if (iSh!=g_iShCur) {
  fnSetTabProps(g_iShCur,false);
  fnSetTabProps(iSh,true);
  g_iShCur=iSh;
 }
}

 window.g_iIEVer=fnGetIEVer();
 if (window.g_iIEVer>=4)
  fnBuildFrameset();
//-->
</script>
<![endif]><!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Daily13</x:Name>
    <x:WorksheetSource HRef="1000.files/sheet001.htm"/>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Intra13</x:Name>
    <x:WorksheetSource HRef="1000.files/sheet002.htm"/>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:Stylesheet HRef="1000.files/stylesheet.css"/>
  <x:WindowHeight>6225</x:WindowHeight>
  <x:WindowWidth>13995</x:WindowWidth>
  <x:WindowTopX>480</x:WindowTopX>
  <x:WindowTopY>120</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
 <x:ExcelName>

Open in new window

document.getElementById("frame1").contentWindow.document.body.style.marginTop='0';
document.getElementById("frame1").contentWindow.document.body.style.marginLeft='0';


document.getElementById("frame1").contentWindow.document.body.style.overflow:'auto';

If you get javascript error on these lines, please send te error, and the navigator app name and version
I used notepad for edit, sorry about that there is
error and input enter key could not make redirect URL
document.getElementByI("frame1").contentWindow.document.body.style.overflow:'auto';
if overflow='auto', it is back to normal but display no change

For these two, everything is same as before
document.getElementById("frame1").contentWindow.document.body.style.marginTop='0';
document.getElementById("frame1").contentWindow.document.body.style.marginLeft='0';

Do you thin free website for javascritp debugger software
Do you have free website for javascript debugger  software
Please wait,  donwloading javascript editor
I use Mozilla Firefox to debug javascript

Just load the page and then go to
Tools / Error Console

If  you want,
post here all the files (individualle) you are using actually, and i can help you fixing it.
Yes, Please wait
Step-1

Download  onkeydown.html  and convert 66666.xls to 66666.htm in Excel which
also generate 66666.files to store all sheet.htm.
Step-2

 Please change the "file:///D:/yourdirectory/" in onkeydown.html  for your directory which  store 66666.htm or 66666.xls

function formSubmit() {

  var my_val = document.getElementById('text1').value;
  // check if value is empty
  if ( my_val.length > 0) {
    document.getElementById("frame1").src="file:///D:/yourdirectory/"+ my_val +".htm";
 
  }

}


Step 3-
At input box when onkeydown.html is in IE window and type 66666 and it will redirect to
"file:///D:/yourdirectory/66666.htm"



Please help and advise

 
66666.xls
onkeydown.html
Dear wmadrid1

Please download the new 6666.xls again since the previous one data is too small, we could not see
the problem. I add more data row and col in the xls  so you see the scroll bar in the second frame .


66666.xls
I supposs you are using IE6

The "margin" is done in tables in te excel process conversion
on lines:
  "<tr><td colspan=6 height=1 bgcolor="+c_rgszClr[2]+"></td></tr>"+
  "<tr><td style=\"font:1pt\">&nbsp;<td>"+


If you want avoid double scrollbars, the best way is make the iframe with a less eight and width than the current IE6 window

you can do it with this lines:
document.getElementById("frame1").height=document.body.offsetHeight-10;
document.getElementById("frame1").width=document.body.offsetWidth-10;


I attach onkeydown.html with these changes

Added
onLoad="setSize();" 

Open in new window

on iframe tag

Added
<script type="text/javascript">
function setSize()
{
//document.getElementById("frame1").height=document.body.scrollHeight-10;
//document.getElementById("frame1").width=document.body.scrollWidth-10;
document.getElementById("frame1").height=document.body.offsetHeight-10;
document.getElementById("frame1").width=document.body.offsetWidth-10;
}
</script>

Open in new window

After body tag
onkeydown.html
For first question, you mean I don't need to do anything because excel will take care
and for second question, after I run your html, I could redirect the page. Is it because
setsize() block the redirect. I already setup correct path .
document.getElementById("frame1").src="file:///D:/mydirectory/"+ my_val +".htm";





Please advise
Sorry typing mistake, I could not redirect the page
For first question, you mean I don't need to do anything because excel will take care
and for second question, after I run your html, I could "NOT"redirect the page. Is it because
setsize() block the redirect. I already setup correct path .
document.getElementById("frame1").src="file:///D:/mydirectory/"+ my_val +".htm";
Dear wmadrid1


For question-1, I tried it is better onMozilla Firefox green color frame is merged into blue frame that is what you said Excel already
take of this. But in my IE7, it is same as before no any change.

For question, After adding setsize with three different ways, the result is same as before no matter in Firefox or IE7

1-
//document.getElementById("frame1").height=document.body.scrollHeight-10;
//document.getElementById("frame1").width=document.body.scrollWidth-10;
document.getElementById("frame1").height=document.body.offsetHeight-10;
document.getElementById("frame1").width=document.body.offsetWidth-10;
2-
document.getElementById("frame1").height=document.body.scrollHeight-10;
document.getElementById("frame1").width=document.body.scrollWidth-10;
//document.getElementById("frame1").height=document.body.offsetHeight-10;
//document.getElementById("frame1").width=document.body.offsetWidth-10;
3-
document.getElementById("frame1").height=document.body.scrollHeight-10;
document.getElementById("frame1").width=document.body.scrollWidth-10;
document.getElementById("frame1").height=document.body.offsetHeight-10;
document.getElementById("frame1").width=document.body.offsetWidth-10;



Please advise, do you have IE7, could you try it at your side
If you drag the IE or Firefox window at right bottom corner to wider width, it will show
the image as attached
Snap26.jpg
The input box will shfit to the bottom in IE window/Firefox
And double scroll bar is still here no matter way you try in setsize() in firefox and IE

The only improvement is that you told the margin problem in question-1 is better in Firefox but not in IE

Please advise, it seems we should use frame and framset instead of iframe. Actully what is major diffferent
if we want actually solve the issues?
Or we can set input box as second frame and 6666.htm set as first frame so that
to avoid double scroll bar ? If input box can be iframe, it can go anywhere in
the webpage
ASKER CERTIFIED SOLUTION
Avatar of wmadrid1
wmadrid1
Flag of Colombia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it seems margin issue is fixed and can be controlled and no need edit in excel htm file.
For Scroll bar , since at the beginning I am using iframe that might be issue since Excel sheet is using <frame>
and finally frame is ok to control scroll bar disable.
using  
Thanks for your reply

Duncan