document.URL with popup

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • katasterisma
    New Member
    • Jun 2007
    • 9

    document.URL with popup

    I have search a lot in the web, but I was not able to find something useful!!

    SCENARIO:

    I have my home page and I open a pop-up window.

    The user can browse in the pop-up window seeing pages that aren't mine web pages!

    PROBLEM:

    At this point I would like to get the pop-up actual URL!

    SOLUTION:

    I tried to use document.URL but nothing it use the main windows and not the pop-up like I want.

    Obviously the pop-up window has a name and I try to use it in document.URL, but nowhere there is an example using it!

    So I hope you can help me I would like to make it possible!!

    thanks you so much
    saludos
  • merseyside
    New Member
    • Mar 2007
    • 48

    #2
    Originally posted by katasterisma
    I have search a lot in the web, but I was not able to find something useful!!

    SCENARIO:

    I have my home page and I open a pop-up window.

    The user can browse in the pop-up window seeing pages that aren't mine web pages!

    PROBLEM:

    At this point I would like to get the pop-up actual URL!

    SOLUTION:

    I tried to use document.URL but nothing it use the main windows and not the pop-up like I want.

    Obviously the pop-up window has a name and I try to use it in document.URL, but nowhere there is an example using it!

    So I hope you can help me I would like to make it possible!!

    thanks you so much
    saludos
    You may find this of some use...

    JavaScript is a programming language that is primarily used to create interactive and dynamic website content. It can be used to manipulate the Document Object Model (DOM) in a web page, making it a popular choice for creating dynamic user interfaces and web applications.

    Comment

    • katasterisma
      New Member
      • Jun 2007
      • 9

      #3
      Originally posted by merseyside

      Thank you so much the link is really interesting, but I can't find in it the solution to my problem!!


      The problem's still the same, I am not able to open a popup and get back with a link in the main page the exact popup's url at that moment!


      Any idea??

      thanks in advance

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        When you open the popup, keep a reference to the popup.

        Then [CODE=javascript]popupref.window .location.href[/CODE] gives you the URL.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by acoder
          When you open the popup, keep a reference to the popup.

          Then [CODE=javascript]popupref.window .location.href[/CODE] gives you the URL.
          It can be done using document.locati on.href.
          Right?

          Kind regards,
          Dmjpro.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by dmjpro
            It can be done using document.locati on.href.
            Right?
            Yes, that could work, but location is a Window object property (link).

            Comment

            • katasterisma
              New Member
              • Jun 2007
              • 9

              #7
              Originally posted by acoder
              Yes, that could work, but location is a Window object property (link).
              Thank you I tried it yet, but nothing.

              This is the code:

              Code:
              function pop(url)
              {
              if(false == my_window.closed)
              {
              my_window.close (); 
              }
              my_window=window.open("http://"+url+"", "M", "width="+screeRes+", height=2000, location=yes, status=yes, resizable=yes, scrollbars=yes, fullscreen=no, toolbar=yes, left=200"); 
              }
               
               
              function test(){
               
              var currentURL = my_window.window.location.href;
              pop(currentURL);
              }

              The problem is the test function, I am not able to make it work.
              May be there's no answer to my question!!

              Thank you all.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                You will have to open the popup window first before you can call test().

                Is my_window a global variable? Do you get any errors?

                Comment

                • katasterisma
                  New Member
                  • Jun 2007
                  • 9

                  #9
                  Originally posted by acoder
                  You will have to open the popup window first before you can call test().

                  Is my_window a global variable? Do you get any errors?

                  I call pop(url) and then call test(), my_window is global!

                  I haven't get sintax error!
                  The problem is that my_window.windo w.location.href don't give me back the current pop up url!

                  At this point I image that there is no solution at this problem and that the inter-window communication don't let me do that!

                  I have read a lot of book section and I was not able to find solution!

                  I try to explicate again the problem (surely my english don't let me express what I really want to express)

                  So:

                  I have my home page.

                  In my home page I have a link to pop(an_url) so when I click it a pop up window is open.

                  In that pop up I can browse like a normal page so I may open www.google.com.

                  At this point with the test() function, called from my home page, I would like to get the pop up url, in this case www.google.com.


                  Solution:

                  I was not able to get it working, I tried with document.url window.location .href and so on but nothing.


                  By the way lot of thanks to everyone tried to help me.

                  Any new suggestion is appreciated!

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Maybe, the url is incorrect. location.href will give you the full URL, but you are adding "http://" to the front of it.

                    If you still have problems, post the full code.

                    Comment

                    • katasterisma
                      New Member
                      • Jun 2007
                      • 9

                      #11
                      I put in the relevant code.

                      So in my html page I have this
                      Code:
                      <p><a onclick="pop('www.google.com')"> open pop up</a></p>
                      <p><A onclick="test();">grab url </a></p>
                      
                      <div id="sinistra"></div>
                      and in the javascript.js file I have

                      Code:
                      var my_window = true
                      
                      function pop(nome)
                      {
                      if(false == my_window.closed)
                       {
                         my_window.close (); 
                       }
                      
                      my_window = window.open("http://"+nome+"","M","width="+screeRes+",height=2000,location=yes,status=yes,resizable=yes,scrollbars=yes,fullscreen=no,toolbar=yes,left=200"); 
                      
                      }
                      
                      function test(){
                      
                      var currentURL = my_window.window.location.href;
                      
                      getElementById('sinistra').innerHTML = currentURL;
                      
                      }

                      I changed the last part of code to make it as simple as possible and test it,
                      but it doesn't work anyway.

                      Thank acoder to spend your time trying to help me. :-)

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Line 18 should be document.getEle mentById('...')

                        Comment

                        • katasterisma
                          New Member
                          • Jun 2007
                          • 9

                          #13
                          Originally posted by acoder
                          Line 18 should be document.getEle mentById('...')

                          You are right but I use an Italian version of this function so I translated it just for readability. The problem isn't the code.

                          No article treat this argument, I was not able to find in internet a complete explication of use of window.location .href, most of them are just a mention to it!

                          I tried it with different browsers with the same result, nothing!

                          So what I am interested in is to find a complete explication of this metod and try to modify it to obtain what I really want!

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            Originally posted by katasterisma
                            No article treat this argument, I was not able to find in internet a complete explication of use of window.location .href, most of them are just a mention to it!
                            See this link. Your code should work. You just want the URL to display in the div, do you?

                            Comment

                            • katasterisma
                              New Member
                              • Jun 2007
                              • 9

                              #15
                              Originally posted by acoder
                              See this link. Your code should work. You just want the URL to display in the div, do you?
                              yes I would like to display the url of the popup.

                              In the link you posted (thanks) I can read this:


                              w3schools

                              Window Object

                              The Window object is the top level object in the JavaScript hierarchy.

                              The Window object represents a browser window.

                              A Window object is created automatically with every instance of a <body> or <frameset> tag.
                              At this point I don't know how to understand it:
                              if I have two windows object (like my case) can I get information from each of them in the same window?
                              or each window can manage just itself information ?
                              But If I open new window like this my_window = window.open(... ......); I suppose that wherever I am in my javascript code I should be able to obtain information from that variable, or not?
                              If yes, how??

                              The most useful and complete explication of window.location I have found is:

                              Location Object

                              The Location object deals with the URL of the current window object. It contains properties and methods to allow you to analyze and change this URL. The Location object contains 8 properties and 2 methods as summarized here:

                              Property Summary for Location Object
                              hash Specifies an anchor name in the URL.
                              host Specifies the host and domain name,
                              or IP address, of a network host.
                              hostname Specifies the host:port portion of the URL.
                              href Specifies the entire URL.
                              pathname Specifies the URL-path portion of the URL.
                              port Specifies the communications port that the server uses.
                              protocol Specifies the beginning of the URL, including the colon.
                              search Specifies a query

                              Method Summary for Location Object
                              reload() Forces a reload of the window's current document. N3+, IE4+
                              replace() Loads the specified URL over the current history entry. N3+, IE4+

                              The href property contains the complete URL and the remaining 6 properties allow you to get various portions of this URL. The href property is the most commonly used one and will be the one that is discussed here.

                              Using document.write( window.location .href), I can determine that the URL of this page is:

                              http://www.javascriptm all.com/learn/lesson11.htm

                              I can also load a new page using the location object. Shown below are three ways that you can do this:

                              window.location = "http://www.JavaScriptM all.com"
                              window.location .href = "http://www.JavaScriptM all.com"
                              location.href = "http://www.JavaScriptM all.com"

                              The top method is the recommended one. This is one case where it is best to use the window in the dot syntax statement. The reason is the document object also contains a location property and JavaScript will sometimes use it instead of this location object when the window keyword is omitted as shown in the third example (The location property of the document object is being phased out by Netscape who no longer documents the property.). Netscape's documentation says that the first two statements are identical but gives no explanation as to why the first method works best. Danny Goodman's JavaScript Bible pointed out that the first statement will work in Internet Explorer 3 where the second is not always dependable. So the bottom line is to use the technique show in this example to load a web page into a single window.

                              window.location = "http://www.JavaScriptM all.com"

                              If you are using frames then you will need learn to use the keywords parent or top, both essentially mean the same thing. The parent keyword refers the frame that contains the <FRAMESET> tags. It is the top most frame. To get the URL of the top frame, or to load a page into it, you use the parent keyword in place of window, parent.location . You can also load refer to one of the frames provided that you have named the frame in your <FRAMESET> tag. You refer to a specific frame by using parent.nameOfFr ame.location. Two of the problems in this lesson's Assignment deal with frames and demonstrates how information stored in the parent frame can be used by all the frames in the set.
                              But doesn't mention the case with two different windows object that I need!


                              I will try to change the layout of the code using a completely different strategy to obtain what I need, but certainly it is really strange that no-one has ever tried it!!

                              Thanks acorder for you patience.

                              Comment

                              Working...