passing url var from a frameset using document.write

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott

    #1

    passing url var from a frameset using document.write

    I need help to modify the code below to pass url variables from a
    framset. The click to run this will be in the mainFrame.

    This script works well in a non-frame page. Grabs the current url
    variables and adds them to my url.

    <script type="text/javascript">
    //<![CDATA[
    document.write( '<a href="my_url.cf m?actionID=clos e&' +
    location.search .substring(1) + '"><img src="launch.jpg " width="75"
    height="30" border="0"></a>');
    //]]>
    </script>


    Thanks in advance.
  • mscir

    #2
    Re: passing url var from a frameset using document.write

    Scott wrote:[color=blue]
    > I need help to modify the code below to pass url variables from a
    > framset. The click to run this will be in the mainFrame.
    >
    > This script works well in a non-frame page. Grabs the current url
    > variables and adds them to my url.
    >
    > <script type="text/javascript">
    > document.write( '<a href="my_url.cf m?actionID=clos e&' +
    > location.search .substring(1) + '"><img src="launch.jpg " width="75"
    > height="30" border="0"></a>');
    > </script>[/color]

    Can you take care of it using one of these approaches:



    if (location.searc h)
    frameSRC = location.search .substring(1);
    else
    frameSRC = "Put the name of the default frame page here";



    http://p2p.wrox.com/archive/beginnin.../2002-03/0.asp

    (location.searc h ? location.search .substring(1):' default.htm') + '">');


    similar:



    Mike

    Comment

    • scott

      #3
      Re: passing url var from a frameset using document.write


      Thanks for the reply. Unforutnately I can only use javascript to obtain
      the url var from the frameset and pass it along to a coldfusion page. I
      am working on a server with alot of restrictions, so it is javascript or
      bust.


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • scott

        #4
        Re: passing url var from a frameset using document.write


        Just realized that I spoke too soon. (sorry late night), the links you
        sent were to js not asp. please accept my apology. I will check those
        out now and report back.


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • mscir

          #5
          Re: passing url var from a frameset using document.write

          scott wrote:[color=blue]
          > Just realized that I spoke too soon. (sorry late night), the links you
          > sent were to js not asp.[/color]

          Maybe see if you can work with one of these if those don't work out for you:

          top.location.hr ef
          window.location .href

          alert('top.loca tion.href\n'+to p.location.href +'\nwindow.loca tion.href\n'+wi ndow.location.h ref);

          Good Luck,
          Mike

          Comment

          • Scott

            #6
            Re: passing url var from a frameset using document.write

            Mike, thanks again for the help. I am very shaky with js.

            I reviewed those links, and I think I should clarify my problem a bit
            more. It appears those links explain how to work with js to either
            pass or pull data so that js can render the framesets for you.


            I need to use js to read the url variables from a frameset page. I am
            very average with js, but I think my solution would be something like
            adding to the script to let it know I was working in a frameset.


            How would I grab everything after the questionmark in the following
            url from a frameset and append it to a link.

            So that this
            foo.com?var1=12 34&var2=5678

            Gets me this
            myUrl.com?var1= 1234&var2=5678

            Thanks again!!

            Comment

            • mscir

              #7
              Re: passing url var from a frameset using document.write

              Scott wrote:
              <snip>[color=blue]
              > I need to use js to read the url variables from a frameset page. >
              > How would I grab everything after the questionmark in the following
              > url from a frameset and append it to a link.
              >
              > So that this
              > foo.com?var1=12 34&var2=5678
              >
              > Gets me this
              > myUrl.com?var1= 1234&var2=5678[/color]

              Sorry I wasn't clearer in my last message, see if this will work for
              you. It takes advantage of "top" which will jump you directly to the top
              of the frame tree, so you can do a location.search on the top window
              from any frame, this worked in my IE6, Netscape7, Firefox 0.8.

              function show() {
              alert('top.loca tion.search ' + top.location.se arch);
              alert('top.wind ow.location.sea rch '+top.window.lo cation.search);
              alert('top.wind ow.location.sea rch.substring(1 )
              '+top.window.lo cation.search.s ubstring(1));
              }

              To read about using "top":


              Learn to write JavaScript that works across HTML frames using frame tree navigation with top, parent, and child references.


              Good Luck,
              Mike

              Comment

              • Grant Wagner

                #8
                Re: passing url var from a frameset using document.write

                Scott wrote:
                [color=blue]
                > I need help to modify the code below to pass url variables from a
                > framset. The click to run this will be in the mainFrame.
                >
                > This script works well in a non-frame page. Grabs the current url
                > variables and adds them to my url.
                >
                > <script type="text/javascript">
                > //<![CDATA[
                > document.write( '<a href="my_url.cf m?actionID=clos e&' +
                > location.search .substring(1) + '"><img src="launch.jpg " width="75"
                > height="30" border="0"></a>');
                > //]]>
                > </script>
                >
                > Thanks in advance.[/color]

                The frames in a frameset have no access to any information passed on
                the URI, because they are defined as:

                <frame src="somepage.h tml" ... />

                Even if the frameset file containing the above HTML was passed items
                on the URI, somepage.html will have no access to that information
                because it is being requested without them. If you what you want is
                somepage.html to have access to information passed to the frameset
                containing it, then use:

                frameset.html ---

                html>
                <head>
                </head>
                <script type="text/javascript">
                var query = window.location .search.substri ng(1);
                if (query != '') {
                query = '&' + query;
                }
                document.write(
                '<frameset rows="86,*" border="0">' +
                '<frame name="top_frame " src="top.html?p age=top' +
                query +
                '" noresize="nores ize" scrolling="no" marginheight="0 "
                marginwidth="0" />\r\n' +
                '<frame name="body_fram e" src="body.html? page=body' +
                query +
                '" noresize="nores ize" marginheight="0 " marginwidth="0" />' +
                '</frameset>'
                );
                </script>
                </html>

                top.html and body.html ---

                <html>
                <head>
                </head>
                <body onload="alert(w indow.location. search);">
                </body>
                </html>


                Load frameset.html?x =y and you should see that passed to both top.html
                and body.html.

                --
                | Grant Wagner <gwagner@agrico reunited.com>

                * Client-side Javascript and Netscape 4 DOM Reference available at:
                *


                * Internet Explorer DOM Reference available at:
                *
                http://msdn.microsoft.com/workshop/a...ence_entry.asp

                * Netscape 6/7 DOM Reference available at:
                * http://www.mozilla.org/docs/dom/domref/
                * Tips for upgrading JavaScript for Netscape 7 / Mozilla
                * http://www.mozilla.org/docs/web-deve...upgrade_2.html


                Comment

                Working...