problem with insertAdjacentHTML

P

Phil

Hi all,

I am trying to use the code below so as to create a frame source string
dynamically. The idea is to verify if this index page is the parent or if it
called by an orphan page, in which case the orphan page passes its own name
as an argument to the index page.
Unfortunately, the code below returns an unspecified error.
This code is what is intended to create the index.htm page as it opens.

<HTML><TITLE>....</TITLE>

<SCRIPT type="text/javascript">
function window.onload()
{
checklocation();
}
function writetop()
{
document.body.insertAdjacentHTML('beforeEnd','<FRAMESET cols=20%,*
FRAMEBORDER="1" BORDER="1" scrolling=auto>')
document.body.insertAdjacentHTML('beforeEnd','<noframes>')
document.body.insertAdjacentHTML('beforeEnd','</noframes>')
}
function writebottom()
{
document.body.insertAdjacentHTML('beforeEnd','</FRAMESET>')
document.body.insertAdjacentHTML('beforeEnd','</HTML>')
}
function checklocation()
{
//alert(top.location.href.length);
var theData;
var begin;
begin = top.location.href.indexOf("?");
if (begin > 0 )
{
theData = top.location.href.substring(begin+1,location.href.length);
theData = unescape(theData);
writetop();
document.body.insertAdjacentHTML('beforeEnd','<FRAME name=main
src="files/ + theData + ">')
}
else{
writetop();
document.body.insertAdjacentHTML('beforeEnd','<FRAME name=main
src="files/Help.htm">')
}
writebottom();
}
</script>
<body>

</body>
</html>
TIA
Phil
http://uk.geocities.com/philippeoget/a2z/
 
M

Mike

Here is perhaps a simplier way to accomplish your goals:

<HTML><TITLE>....</TITLE>

<SCRIPT type="text/javascript">
//alert(top.location.href.length);
var theData;
var begin;
var url = "files/Help.htm";
begin = top.location.href.indexOf("?");
if (begin > 0 )
{
theData = top.location.href.substring(begin+1,location.href.length);
theData = unescape(theData);
url = "files/ + theData;
}
</script>
<FRAMESET cols="20%,*" FRAMEBORDER="1" BORDER="1" scrolling="auto">
<script type="text/javascript">
document.write("<FRAME name=main src='"+ url+"'>";
</script>
</FRAMESET>
</html>


One thing to notice is that you are missing a FRAME definition. I don't know
if that is intentional or not but perhaps that is the reason for your error
because you specify 2 frames in your frameset (cols="20%,*) but then only
define one.
 
M

Mick White

Mike said:
Here is perhaps a simplier way to accomplish your goals:

<HTML><TITLE>....</TITLE>

<SCRIPT type="text/javascript">
//alert(top.location.href.length);
var theData;
var begin;
var url = "files/Help.htm";
begin = top.location.href.indexOf("?");
if (begin > 0 )
{
theData = top.location.href.substring(begin+1,location.href.length);
theData = unescape(theData);
url = "files/ + theData;
}
</script>

You are missing quotes after "files/
Even simpler below?
<SCRIPT type="text/javascript">
var url = "files/Help.htm";
if (top.location.search ){
url = "files/" + unescape(top.location.search.substring(1))
}
</script>

Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top