www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: [RESOLVED] Trying to access src attribute in frame tag

  1. #1
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    resolved [RESOLVED] Trying to access src attribute in frame tag

    Hi all;

    I'm trying to access the src attribute in a pair of frame tags to append
    a query string to the end - as obtained by a function from the opening page.


    The mess that follows is all of the stuff that I've tried:
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    function set_src_on_frames ()
    {
    var fTag;
    var Qstr = opener.get_the_querystring ();


    //fTag = document.getElementById("frame_01");

    //if (fTag === null) alert (' fTag is null');

    //fTag.setAttribute
    //parent.frames['frame_01'].document.setAttribute
    //document.frames['frame_01'].setAttribute
    //frames['frame_01'].setAttribute
    frameset.frames['frame_01'].document.setAttribute
    ('src', 'http://localhost/CPST02a.aspx' + '?' + Qstr);

    //fTag = document.all.getElementById("frame_02");

    //fTag.setAttribute
    //parent.frames['frame_02'].document.setAttribute
    //document.frames['frame_01'].setAttribute
    //frames['frame_01'].setAttribute
    frameset.frames['frame_02'].document.setAttribute
    ('src', 'http://localhost/CPST02b.aspx' + '?' + Qstr);
    }

    set_src_on_frames ();


    // -->

    </script>

    </head>

    <frameset rows="30%,70%">
    <frame id="frame_01" src=""
    name="CPSTrans02a">
    <frame id="frame_02" src=""
    name="CPSTrans02b">
    </frameset>
    </html>

    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


    This is something that someone who is familiar with javascript might know
    off the top of their heads. Unfortunately (for myself), I'm not one of those
    people who are familiar with javascript.

    How do I reference an element within a frame tag?

    Any help with this would be greatly appreciated.

    THANKS!!!

  2. #2
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    Unhappy Tried this

    Hi again all;


    I tried using Javascript entities - without success:
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    function set_the_path (the_file)
    {
    var Qstr = opener.get_the_querystring ();

    return (the_file + '?' + Qstr);
    }

    var the_path = set_the_path ("CPST02a.aspx");
    var the_2_path = set_the_path ("CPST02b.aspx");

    // -->

    </script>

    </head>

    <frameset rows="30%,70%">
    <frame id="frame_01" src="&{the_path};"
    name="CPSTrans02a">
    <frame id="frame_02" src="&{the_2_path};"
    name="CPSTrans02b">
    </frameset>
    </html>

    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



    Consequently, IE tried to use the following to reference a page:
    http://localhost/&{the_path};

    Any help with this would be appreciated!!!

    THANKS!!!

  3. #3
    Join Date
    Feb 2008
    Posts
    1,666
    If the frames/iframes are not for a document in the same domain, then forget it. Otherwise, it is best to go after the location object -- not the src attribute.

    self.frames['frameName'].location.href

  4. #4
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    Unhappy Not sure

    Hi Mr Nobody!

    I'm not sure where I should put that line of code.

    If I put it above the frameset tags, I get the following:

    "self.frames['frameName'].location is null or not an object"

    If I put it below the tags, I don't get anything.

    Apparently, the tags have executed before the Javascript has had a chance
    to do anything.

    THANKS for the response!!!

  5. #5
    Join Date
    Feb 2008
    Posts
    1,666
    The frames should have names -- not ids. Then, you can use that code in your function to set the url for the frames using the location object -- not the src attribute.

  6. #6
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    Unhappy Still NULL

    Quote Originally Posted by MrNobody View Post
    The frames should have names -- not ids. Then, you can use that code in your function to set the url for the frames using the location object -- not the src attribute.
    I know - the frames have names - and that's what I'm using - but I still
    get a friggin' null reference - and it's driving me nuts!!!

    I'll keep plugging - there's got to be a reason why its null.

    ... and THANKS!!!

  7. #7
    Join Date
    Feb 2008
    Posts
    1,666
    Well, the HTML you posted has ids -- that is why I said something. Don't shoot the messenger.

  8. #8
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64
    Quote Originally Posted by MrNobody View Post
    Well, the HTML you posted has ids -- that is why I said something. Don't shoot the messenger.
    Hi Mr Nobody;

    Yes - they have id's - but they also have names.

    I was trying the id's in the hope that it might get a result of some kind.

    Not shooting the messenger here - I want you to know that - and know that
    your assistance is greatly appreciated. AAMOF, you might have given me
    the answer, it's just that - for reasons not yet known to me - the expression
    comes up null.

    THANKS!!!!

  9. #9
    Join Date
    Jun 2004
    Posts
    316
    if you want to set the src tag, you can use document.getElementById("...").src="...";

  10. #10
    Join Date
    Feb 2008
    Posts
    1,666
    If you care to explain to me the process through which you're trying to accomplish something, then I can tell you how to apply the information I've given you.

  11. #11
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    Tried that

    Quote Originally Posted by TheTeenScripter View Post
    if you want to set the src tag, you can use document.getElementById("...").src="...";
    Hi Teen Scripter;

    I tried that - and it didn't work.

    I got a null reference when I did.

    Thanks for the response!!!

  12. #12
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    It shouldn't be this hard - but it is for me.

    Quote Originally Posted by MrNobody View Post
    If you care to explain to me the process through which you're trying to accomplish something, then I can tell you how to apply the information I've given you.
    Hi Mr Nobody;

    As I mentioned in my initial post, I'm just trying to load the paths for the
    Frames within a frameset dynamically using Javascript. This shouldn't be
    anything difficult, but it seems to be for me - maybe I'm just dense or
    something:
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    function set_src_on_frames ()
    {
    var Qstr = opener.get_the_querystring ();

    // This is the stuff that I've tried - to no avail:
    //parent.frames['frame_01'].document.setAttribute
    //document.frames['frame_01'].setAttribute
    //frames['frame_01'].setAttribute

    frameset.frames['frame_01'].document.setAttribute
    ('src', 'http://localhost/CPST02a.aspx' + '?' + Qstr);


    // This is the stuff that I've tried - to no avail:
    //parent.frames['frame_02'].document.setAttribute
    //document.frames['frame_01'].setAttribute
    //frames['frame_01'].setAttribute

    frameset.frames['frame_02'].document.setAttribute
    ('src', 'http://localhost/CPST02b.aspx' + '?' + Qstr);
    }

    set_src_on_frames ();


    // -->

    </script>

    </head>

    <frameset rows="30%,70%">
    <frame src="" name="CPSTrans02a">
    <frame src="" name="CPSTrans02b">
    </frameset>
    </html>

    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



    I've also tried this:
    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

    var path_1;
    var path_2;

    function set_paths ()
    {
    var Qstr = opener.get_the_querystring ();

    path_1 = 'http://localhost/CPST02a.aspx' + '?' + Qstr);
    path_2 = 'http://localhost/CPST02b.aspx' + '?' + Qstr);
    }

    set_paths ();


    // -->

    </script>

    </head>

    <frameset rows="30%,70%">
    <frame src="javascriptath_1" name="CPSTrans02a">
    <frame src="javascriptath_2" name="CPSTrans02b">
    </frameset>
    </html>

    -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


    The above got me a blank page, with the URL written to it as text.



    THANKS!!!

  13. #13
    Join Date
    Feb 2008
    Posts
    1,666
    OK, you cannot execute your function before the frameset document renders. Given this:
    HTML Code:
    <frameset rows="30&#37;,70%">
    <frame src="" name="CPSTrans02a">
    <frame src="" name="CPSTrans02b">
    </frameset>
    These references will load their respective frames -- once those frames have completed rendering.
    Code:
    top.frames['CPSTrans02a'].location.href = "...url1...";
    top.frames['CPSTrans02b'].location.href = "...url2...";
    You can delay the execution of your function as follows:
    Code:
    window.onload = set_src_on_frames;

  14. #14
    wylbur is offline Wylbur the Possum-Hearted
    Join Date
    Apr 2006
    Location
    South Texas
    Posts
    64

    Unhappy still NULL

    Quote Originally Posted by MrNobody View Post
    OK, you cannot execute your function before the frameset document renders. Given this:
    HTML Code:
    <frameset rows="30%,70%">
    <frame src="" name="CPSTrans02a">
    <frame src="" name="CPSTrans02b">
    </frameset>
    These references will load their respective frames -- once those frames have completed rendering.
    Code:
    top.frames['CPSTrans02a'].location.href = "...url1...";
    top.frames['CPSTrans02b'].location.href = "...url2...";
    You can delay the execution of your function as follows:
    Code:
    window.onload = set_src_on_frames;


    Hi Mr. Nobody;

    I thought for sure you had given me the answer when I first read your post.
    I was crestfallen when I got the same friggin' error messages for a null reference.

    These are the messages that I got, as I tried each option from the code below
    (in reset_URLs_in_frameset):

    ERROR: 'top.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'self.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'window.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'self.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'self.frames["CPSTrans02a"].document' is null or not an object

    Code:
       //  ======================================================
    
       function get_path (the_path)
       {
           var QString = window.opener.get_active_query_string ();
    
           if (QString === null)
                   return   the_path;
           else    return   the_path + '?' + QString;
       }
       //  ======================================================
    
       function reset_URLs_in_frameset ()
       {
           var path_a = "http://localhost/CtrlInitVDir/CPSTrans02a.aspx";
           var path_b = "http://localhost/CtrlInitVDir/CPSTrans02b.aspx";
    
           //top.frames["CPSTrans02a"].location.href = get_path (path_a);
           //self.frames["CPSTrans02a"].location.href = get_path (path_a);
           //window.frames["CPSTrans02a"].location.href = get_path (path_a);
           //self.frames["CPSTrans02a"].setAttribute ('src', get_path (path_a));
    
           self.frames["CPSTrans02a"].document.setAttribute
                                                      ('src', get_path (path_a));
    
    
           //top.frames["CPSTrans02b"].location.href = get_path (path_b);
           //self.frames["CPSTrans02b"].location.href = get_path (path_b);
           //window.frames["CPSTrans02b"].location.href = get_path (path_b);
           //self.frames["CPSTrans02b"].setAttribute ('src', get_path (path_b));
    
           self.frames["CPSTrans02b"].document.setAttribute
                                                      ('src', get_path (path_b));
    
       }
       //  ======================================================
       //  ======================================================
    
       window.onload = reset_URLs_in_frameset ();
    
    // src="http://localhost/CtrlInitVDir/CPSTrans02a.aspx"
    // src="http://localhost/CtrlInitVDir/CPSTrans02b.aspx"
    
    // -->
    </script>
    
    </head>
    
    <frameset rows="30%,70%">
      <frame name="CPSTrans02a">
      <frame name="CPSTrans02b">
    </frameset>
    </html>

    I continue to be bedeviled by this.


    THANKS for the responses/advice!!!

  15. #15
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    ERROR: 'top.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'self.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'window.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'self.frames.CPSTrans02a.location' is null or not an object
    ERROR: 'self.frames["CPSTrans02a"].document' is null or not an object
    those errors are because instead of assigning the function to the onload event, you are calling it. and then come what mrnobody has explained you in post #13 "not to execute the function before document render". this is the line in question according to your code:
    Code:
    window.onload = reset_URLs_in_frameset ();
    notice that mrnobody example don't include the function call (the parenthesis).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles