www.webdeveloper.com
Results 1 to 4 of 4

Thread: Getting The URL of a page inside a Frame

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Getting The URL of a page inside a Frame

    http://botsuite.com/Screenshot-1.png
    http://botsuite.com/Screenshot-2.pngProblem
    I have an index.html that sets up 3 Frames. They are called FrameTop, FrameA and FrameB. See pic below. In FrameTop the user can type in a url into a textbox with id="urlINPUT". When user clicks LOADA it loads that url into FrameA. User can then browse web in FrameA, clicking links etc and going to new pages. The second button LOADB is designed to determine the current location/url of the page displayed in FrameA and load that into FrameB. So far when I write the javascript in FrameTop LOADA works but LOADB loads the FrameTop into FrameB! [error!]

    If someone can please help me with this problem it would be much appreciated. This work is going towards a free website idea.

    I suspect my error lies in use of parent/self in the parent.frame.location.



    Here is my page layout.
    http://botsuite.com/Screenshot-1.png



    -----------------Index.html-------------------------------------
    <frameset rows="5%,*">
    <frame name="FrameTop" src="frame_top.html" />
    <frameset cols="50%,50%">
    <frame name="FrameA" id="FrameA" src="frame_a.html" />
    <frame name="FrameB" id="FrameB" src="frame_b.html" />
    <noframes>
    </noframes>
    </frameset>


    --------------------frame_top.html-------------------------------
    <SCRIPT language="JavaScript">

    function loadURLintoA() /*gets the url typed in by user and loads it into Frame A. This works fine*/
    {
    var urlrequest= "http://"+document.getElementById('urlINPUT').value;
    parent.FrameA.location.href = urlrequest; /*sets FrameA location to url that user enters in frametop input*/

    }

    </SCRIPT>

    <SCRIPT language="JavaScript">

    function loadAintoB() /*I WANT this to get the url of the website loaded in frame A and load it into frame B*/
    {
    var urlofA = parent.FrameA.location;
    parent.FrameB.location = urlofA; /*this is supposed to get the url of FrameA and load it into FrameB*/

    }

    </SCRIPT>
    </HEAD>

    <body bgcolor="#848484">
    http://<input type="text" name="urlINPUT" value="" id="urlINPUT" size="10">
    <input type="button" name="loadAbutton" id="loadAbutton" value="LOAD A" onclick="loadURLintoA()">
    <input type="button" name="loadBbutton" id="loadBbutton" value="LOAD B" onclick="loadAintoB()">


    ----------------------------------------------

    What happens when I run index.html
    index.html loads the index correctly and displays FrameTop, FrameA and FrameB. The load A button also works correctly BUT when I click LoadB it loads FrameTop into FrameB! This happens when no page is loaded into FrameA AND when an external page in loaded in.

    http://botsuite.com/Screenshot-1.png
    http://botsuite.com/Screenshot-2.png
    http://botsuite.com/Screenshot-3.png

    Please help, I would be very greatfull if you could point out my mistake.

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    Have you tried checking the error console?
    Code:
    function loadAintoB() /*I WANT this to get the url of the website loaded in frame A and load it into frame B*/
    {
      var urlofA ;
    
      try
      {
        parent.FrameB.location.href = parent.FrameA.location.href;
      }
      catch( e )
      {
        alert("OOPS - looks like I tried to read the location of a foreign domain, which obviously is not allowed!\n\nWhat is this obsession with displaying other people's content?");
      }
    }

  3. #3
    Join Date
    Apr 2011
    Posts
    2

    Error Message

    Lol yes, very funny. I should have mentioned why I'm trying to do it. I'm not making some hack site that gets advertising money while you surf, I want a free page that allows the user to surf the same page in two frames with the second frame having a function performed on it. Ie: enlarged text for visually impaired.

    Can you please tell me whether what i am trying to do is possible. I'd really appreciate it

  4. #4
    Join Date
    Mar 2011
    Posts
    81
    This may be of interest, not sure if it will totally address your concerns although.

    https://developer.mozilla.org/en/DOM/window.postMessage

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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