JavaScript and frames issues

  • ahevans
  • Graduate
  • Graduate
  • ahevans
  • Posts: 181

Post 3+ Months Ago

hi, I am trying to use JavaScript to validate what is in a frame in a frame set. The frame set has 2 frames

Code: [ Select ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<frameset cols="*,200" frameborder="yes" border="0" framespacing="0">
<frame src="Untitled-2.htm" name="mainFrame">
<frame src="Untitled-3.htm" name="rightFrame" scrolling="NO" noresize>
</frameset>
<noframes><body>
</body></noframes>
</html>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Untitled Document</title>
  6. </head>
  7. <frameset cols="*,200" frameborder="yes" border="0" framespacing="0">
  8. <frame src="Untitled-2.htm" name="mainFrame">
  9. <frame src="Untitled-3.htm" name="rightFrame" scrolling="NO" noresize>
  10. </frameset>
  11. <noframes><body>
  12. </body></noframes>
  13. </html>


initially the mainframe has a blank page with a link to a website and the right frame has a page with a link in it that goes to page with the following code

Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE" />
<title>Untitled Document</title>
<SCRIPT language="JavaScript">
<!--
function validateframe() {
    if (parent.mainFrame.location.href == "http://www.google.co.uk")
    {
        document.write("Success!");
    }
    else
    {
        document.write("Nothing to see!");
    }
}
//-->
</SCRIPT>
</head>

<body onload="validateframe()">

</body>
</html>
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE" />
  6. <title>Untitled Document</title>
  7. <SCRIPT language="JavaScript">
  8. <!--
  9. function validateframe() {
  10.     if (parent.mainFrame.location.href == "http://www.google.co.uk")
  11.     {
  12.         document.write("Success!");
  13.     }
  14.     else
  15.     {
  16.         document.write("Nothing to see!");
  17.     }
  18. }
  19. //-->
  20. </SCRIPT>
  21. </head>
  22. <body onload="validateframe()">
  23. </body>
  24. </html>


I am using Internet Explorer 7 and Firefox 3. The if statement never validates to true and I found this is because the frame location value is always about:blank regardless of the webpage loaded in the mainframe, so this is my first problem

The second problem is that even if I manipulate the if statement to use about:blank, the expected string is never displayed unless I refresh the frame set after getting things in a state that will validate to true. Refreshing the framesets only works in Firefox and not Internet Explorer, this is my second problem

Can anyone help please?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

The first thing I would try is monitoring the src attribute instead of the location property.
  • ahevans
  • Graduate
  • Graduate
  • ahevans
  • Posts: 181

Post 3+ Months Ago

Hi, I changed my code slightly to use if (parent.mainFrame.location.href == 'http://www.google.co.uk') e.g. single quotes, and if I change the URL to about:blank I can get the if statement to be both true and false

I still have to refresh the frame when the statement is true in order to see the expected message and the frame is still about: blank instead of the proper URL

I tried using parent.mainFrame.location.src and parent.mainFrame.src but the value was undefined and when Googling this doesn't seem to be valid

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 62 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.