Target anchor in an Iframe in a popup

The following shows how you can target an anchor that is in a document loaded into an iframe

Open at anchor 1
Open at anchor 2
Open at anchor 3
Open at anchor 4
Open at anchor 5

In the parent page

<script type="text/javascript">
<!--
function newWin(n){
myWin=window.open("popup_page.htm?"+n,'win1','top=100,left=200,width=400,height=300, scrollbars=yes')
myWin.focus()
}
// -->
</script>

<a href="#null" onclick="newWin('01')">Open at anchor 1</a>
<a href="#null" onclick="newWin('02')">Open at anchor 2</a>
<a href="#null" onclick="newWin('03')">Open at anchor 3</a>
<a href="#null" onclick="newWin('04')">Open at anchor 4</a>
<a href="#null" onclick="newWin('05')">Open at anchor 5</a>

In the popup page

<script type="text/javascript">
<!--
dataPassed=null
function anchor_point(){
if (location.search.length > 0){
dataPassed = unescape(location.search.substring(1));
}
scrollPoint=window.frames["myiframe"].document.getElementById(dataPassed).offsetTop
window.frames["myiframe"].scrollTo(0,scrollPoint)
}

// add onload="anchor_point()" to the opening body tag

// -->
</script>

<iframe name="myiframe" src="iframe_page.htm"></iframe>

In the iframe page
Anchor examples

<P><a id="01" style="background-color:#00AA00;width:100%;height:150px">Anchor 1</a>
<P><a id="02" style="background-color:#AAAA00;width:100%;height:150px">Anchor 2</a>
<P><a id="03" style="background-color:#AA0000;width:100%;height:150px">Anchor 3</a>
<P><a id="04" style="background-color:#0000AA;width:100%;height:150px">Anchor 4</a>
<P><a id="05" style="background-color:#00AAAA;width:100%;height:150px">Anchor 5</a>

If the anchors are in a table in the iframe page then use the following script in the popup page

<script type="text/javascript">
<!-- 
dataPassed=null
moz=document.getElementById&&!document.all

function test(data){

if (location.search.length > 0){
dataPassed = unescape(location.search.substring(1));
}

if(arguments.length!=0){
dataPassed=data
}

if(dataPassed=="null"){
return
}

cellEl=window.frames["myiframe"].document.getElementById(dataPassed)

cellLeftPos = cellEl.offsetLeft
cellTopPos = cellEl.offsetTop
parentEl = cellEl.offsetParent

while (parentEl != null){

if(parentEl.tagName == "TD"){ // if parent a table cell, include cell border width

if(!moz){
cellLeftPos += parentEl.clientLeft
cellTopPos += parentEl.clientTop
}
else{

if(parentEl.tagName == "TABLE"){ // if parent is a table, get its border as a number
nParBorder = parseInt(parentEl.border)

if(nParBorder > 0){ // if a border width is specified
nLeftPos += nParBorder // append the border width to counter
}
}
}
}

cellLeftPos += parentEl.offsetLeft // add left offset of parent
cellTopPos += parentEl.offsetTop // add top offset of parent

parentEl = parentEl.offsetParent; // move up the elements until no more offset parents exist
}

window.frames["myiframe"].scrollTo(cellLeftPos,cellTopPos)

//return "X pos = "+cellLeftPos+"<P>Y pos ="+cellTopPos // return totals

}
// -->
</script>