Menu

document.URL undefined in included JavaScript

Help
2005-06-06
2013-04-26
  • James Tikalsky

    James Tikalsky - 2005-06-06

    I have a test page that creates a JavaScript alert with the current document's URL:

    <html>
        <head>
            <title>Test Suite</title>
        </head>
        <body>
         <script type="text/javascript">
            alert("document.URL: " + document.URL);
         </script>
        </body>
    </html>

    In my unit test, I'm trying to read the document's URL from the alert box, and write that value to the console:

    public class AlertDocumentUrlTest extends TestCase {
       
        public void testAlertDocumentUrl() {
            try {
                WebConversation wc = new WebConversation();
                WebResponse response = wc.getResponse("http://localhost/event/test.html");
                System.out.println(wc.getNextAlert());
            }
            catch (MalformedURLException e) {
                e.printStackTrace();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            catch (SAXException e) {
                e.printStackTrace();
            }
           
        }
       
    }

    The value written to the console is "undefined", not the value of document.URL, as expected.

    Is there some configuration that I need to do to make sure that document.URL value gets set?

    I'm *guessing* that I may need to configure the parser to parse my document as HTML, not XML, and that doing this will give Rhino the hooks it needs to get the data.

    James Tikalsky
    Fort Worth, TX

     
    • James Tikalsky

      James Tikalsky - 2005-06-06

      Investigating further, I see that document.URL may not be supported yet:

      http://httpunit.sourceforge.net/doc/javascript-support.html

      I'll try window.location instead.

       

Log in to post a comment.

MongoDB Logo MongoDB