Jump to content

Need help with JS syntax


watagal

Recommended Posts

Greetings,I'm loading a page into an ajoining frame -- I got it working by hardcoding the frame's ID, but when I pass it the frame's ID -- it breaks.Here's what work:

function loadPage2Frame(sURL) {top.frames["frameMain"].location=sURL;}

Here's what DOES NOT work:

function loadPage2Frame(sFrameID,sURL) {top.frames[sFrameID].location=sURL;}  // where sFrameID = "frameMain"

I get "Error: top.frames[sFrameID] has no properties".I've tried:

top.frames["\""+sFrameID+"\""].location  // Double quotestop.frames["'"+sFrameID+"'"].location  // single quotes

Any ideas on how to do this?thanks

Link to comment
Share on other sites

Did you know that you can test the output of a certain string?Before you use the string as the ID of the frame, maybe you should alert() it to see what JavaScript actually understands from it. :)

Link to comment
Share on other sites

Did you know that you can test the output of a certain string?Before you use the string as the ID of the frame, maybe you should alert() it to see what JavaScript actually understands from it. :)

Thanks Dan -- I put in an alert(sFrameID) and it did report back the name of the frame I was sending it. The funny thing is as soon as I put in the alert() statement, the function worked. As soon as I removed the alert() statement, it fails again with the same error.Any other ideas.Thanks
Link to comment
Share on other sites

GreetingsHere's the function that works with the 'alert()' statement and doesn't work when I comment it out. Please help, I'm just not getting this one.

function togElementDisplay(sFrameID,sElementID) {	if (sFrameID != "")	{  var oDiv = top.frames[sFrameID].document.getElementById(sElementID);	} else {  var oDiv = document.getElementById(sElementID);	}//	alert(oDiv);	oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";}

Error = "Error: oDiv has no properties"

Link to comment
Share on other sites

Can you post the full code instead of snippets please?

Frameset:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252"><title>Notebook</title></head><frameset framespacing="0" border="0" frameborder="0" rows="75,*,25">	<frame name="frmHeader" scrolling="no" noresize target="main" src="SupportPages/header.htm" marginwidth="0" marginheight="0">	<frameset cols="200,*">		<frame name="frmToc" src="SupportPages/toc.htm" marginwidth="0" marginheight="0" scrolling="auto" target="_self">		<frameset rows="101,*,10">			<frame name="frmTopicHeader" src="SupportPages/login_header.htm" scrolling="yes" marginwidth="0" marginheight="0" target="_self">			<frame name="frmTopicMain" src="SupportPages/login_main.htm" marginwidth="0" marginheight="0" scrolling="yes" target="_self">			<frame name="frmComment" src="SupportPages/comments.htm" marginwidth="0" marginheight="0" scrolling="no" target="_self">		</frameset>	</frameset>	<frame name="frmFooter" src="SupportPages/footer.htm" marginwidth="0" marginheight="0" scrolling="no" noresize target="_self">	<noframes>	<body>	<p>This page uses frames, but your browser doesn't support them.</p>	</body>	</noframes></frameset></html>

HTML header.htm:

<html><head>	<meta http-equiv="Content-Language" content="en-us">	<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">	<title>Main Header</title>	<base target="main">	<script language="javascript" src="../../Code/JS/GuiUtils.js"></script>	<script language="javascript" src="../../Code/JS/browserUtils.js"></script>	<script language="javascript">		function loadSignInPages() {			loadPage2Frame(top.frames['frmTopicHeader'],'login_header.htm');			loadPage2Frame(top.frames['frmTopicMain'],'login_main.htm');			togElementDisplay('','divWelcomeName')			togElementDisplay('frmTopicMain','divRegister')//			togElementDisplay(top.frames['frmTopicMain'],'divRegister')		}	</script></head><body text="#EFFEEB" bgcolor="#000000" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="6" marginwidth="0" marginheight="0">	<table width="100%" id="table1" cellspacing="0" cellpadding="0" height="75" style="border-width: 0px">		<tr>			<td style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom: medium none #008080; padding-bottom: 5px">			<p style="margin-left: 15px; margin-top: 0; margin-bottom: 0">			<span style="letter-spacing: 0px">			<font face="Mistral" color="#008080" style="font-size: 55pt">My</font><font face="Mistral" color="#008080" style="font-size: 48pt">'s 			Notebook Series</font></span></p>			<p style="margin-top: 6px; margin-bottom: 0" align="left"> </td>			<td style="border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom: medium none #008080; padding-bottom: 5px" valign="top">			<table border="0" id="table2" cellspacing="0" cellpadding="0" width="100%" height="100%">				<tr>					<td width="100%" valign="top" align="right" height="12">						<div id="divMemberCmds" style="display:none">							<p style="margin-right: 30px; margin-top: 6px; margin-bottom: 0">							<font face="Tahoma" size="1" color="#99CCFF">								<span style="cursor: pointer" onclick="togPanels()">My Account</span>							</font>							<font face="Tahoma" size="1" color="#FFFFFF"><b> | </b></font> 							<font face="Tahoma" size="1" color="#99CCFF">								<span style="cursor: pointer" onclick="togPanels()">Sign Out</span>							</font>							</div>						<div id="divGuestCmds" style="display:none">							<p style="margin-right: 30px; margin-top: 6px; margin-bottom: 0">							<font face="Tahoma" size="1" color="#99CCFF">							<span style="cursor: pointer" onclick="loadSignInPages()">								Register Now							</span>							</font><font face="Tahoma" size="1" color="#C0C0C0">							</font>						</div>					</td>				</tr>				<tr>					<td valign="top" align="right">						<font color="#FFFFFF" face="Tahoma">							<div id="divWelcomeName">								<p style="margin-right: 30px">								Welcome!								</p>							</div>						</font>					</td>				</tr>			</table>			</td>		</tr>	</table></body></html>

My GuiUtils.js:

function welcome(sWho){	var o = top.frames['frmHeader'].document.getElementById('divWelcomeName');	o.innerHTML = "<p style='margin-right: 30px'>Welcome "+sWho+"!</p>";}//	Toggle Single Element on/off//		togElementDisplay('frameTopicMain','divTab2');function togElementDisplay(sFrameID,sElementID) {	if (sFrameID != "")	{		var o = top.frames[sFrameID].document.getElementById(sElementID);	} else {		var o = document.getElementById(sElementID);	}//	alert(oDiv);	o.style.display = (o.style.display == "none") ? "block" : "none";}//	Swap Multiple Elements on/off - i.e. Tab Panels//  	var aElementIDs = ['divTab1','divTab2','divTab3'];						// Defined Once in HTML file//		onclick="swapElementDisplay('frameTopicMain','divTab2',aElementIDs);"	// function swapElementDisplay(sFrameID,sElementID,aElementIDs) {	for (var i=0; (i < aElementIDs.length); i++) {		if (sFrameID != "")	var o = top.frames[sFrameID].document.getElementById(aElementIDs[i]);		else 				var o = document.getElementById(aElementIDs[i]);				if (sElementID != aElementIDs[i])	o.style.display = "none";		else								o.style.display = "block";	}}

I think this is all, thanks for helping out

Link to comment
Share on other sites

Without reading your full code, I think I know whats wrong.You're targeting the document in a frame, aren't you? And the object has no properties. Well, that is simply because those documents are not allowed to be targeted!Only documents from yourself, such as the top one. Every other document may not be one of yours, so targeting is disallowed. You may not adjust or manipulate any document that is not yourself :) Even it actually is but the browser thinks it isn't :)

Link to comment
Share on other sites

You're targeting the document in a frame, aren't you? And the object has no properties. Well, that is simply because those documents are not allowed to be targeted!

Thanks DanYes, I am targeting a document in another frame in the same frameset and/or perhaps in a parent frameset. All are mine (ie they are local to my website).The funny (strange) thing is I can target them with this function below -- as long as I put in the alert() statement - it works. Only when I remove the alert(), it produces the error "Error: oDiv has no properties".
function togElementDisplay(sFrameID,sElementID) {	if (sFrameID != "")	{  var oDiv = top.frames[sFrameID].document.getElementById(sElementID);	} else {  var oDiv = document.getElementById(sElementID);	}//	alert(oDiv);	oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";}

I'm wondering if there is timing issue? Is there a work around?Thanks again for all the help,

Link to comment
Share on other sites

Just to get it clear for me, when the alert is commented out, it does not work, but else it would?If that is so, then it may be timing, but it may also be just the alert.Compare it with this: javascript in the addressbar will not be executed unless it is being alerted. :)So the alert may have a individual purpose..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...