Frameset title tricks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cheesecaker
    New Member
    • Feb 2007
    • 66

    Frameset title tricks

    If I have a frameset page with a frame in it, how would I use JS to get the title of the framed document and set it as the title of the parent frameset page?

    If that makes no sense, please ask for clarification.
  • cheesecaker
    New Member
    • Feb 2007
    • 66

    #2
    Anyone have an idea about this?

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Do you want to set it from the framed page or the frameset?

      Comment

      • cheesecaker
        New Member
        • Feb 2007
        • 66

        #4
        Originally posted by acoder
        Do you want to set it from the framed page or the frameset?
        I want to take the title from the framed page and set it as the browser window's title, to put it simply.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          The reason why I asked was that if the framed page changes, do you now need to update the title?

          To set the title from the framed page:
          [code=javascript]window.onload= function() {
          parent.document .title = document.title;
          }[/code]To set it from the frameset:
          [code=javascript]function changeTitle() {
          document.title = window.frames[frameName].document.title ;
          } [/code]

          Comment

          • cheesecaker
            New Member
            • Feb 2007
            • 66

            #6
            Because of the circumstances of the system I've set up, the frameset will reload every time the framed page reloads. And I need to set the title from the frameset page, but when I do[html]<frameset onload="changeT itle()" ... >[/html], it doesn't seem to work.

            I basically need to set the page title, from the frameset page, as soon as or before the framed page loads. How would that be implemented? I'm really Javascript-dull, sorry. :x

            The name of the frame is "main", by the way.

            Comment

            • cheesecaker
              New Member
              • Feb 2007
              • 66

              #7
              By the way, I stuck an alert("firing") ; in there and it showed up, so the function's being called, I guess the JS isn't right?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Can I see your code? This code works:
                [code=html]<html>
                <script>
                function changeTitle() {
                document.title = window.frames["main"].document.title ;
                }
                </script>
                <frameset cols="50%,50%" onload="changeT itle();">
                <frame src="script.htm ">
                <frame name="main" src="script2.ht m">
                </frameset>
                </html>[/code]

                Comment

                • cheesecaker
                  New Member
                  • Feb 2007
                  • 66

                  #9
                  [html]<script type="text/javascript">
                  function changeTitle() {

                  document.title = window.frames["main"].document.title ;

                  }
                  </script>
                  </head>
                  <frameset rows="100%,*" onload="changeT itle();" frameborder="NO " border="0">
                  <frame name="main" src="http://mysite.com:8080/<?php echo $_GET['page']; ?>">
                  </frameset>[/html]

                  As you can see, there's only one frame involved, and it covers the entire page. It's part of a cloaked redirect system that would hide the ":8080" of a home web server, but I don't see how any of that would stop it from working.

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Are the frameset and frame pages from the same domain?

                    Comment

                    • cheesecaker
                      New Member
                      • Feb 2007
                      • 66

                      #11
                      No. Oh, it's XSS security, isn't it? Gah.

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by cheesecaker
                        No. Oh, it's XSS security, isn't it? Gah.
                        Yes, you can't access pages from another domain. The workaround would be to use some server-side code to get the page and load it into the frame and then document.title would become accessible to the frameset page.

                        Comment

                        Working...