2 Replies Latest reply: Jun 17, 2009 7:54 PM by 793415 RSS

    ScriptEngine to get the URL

    807588
      In JavaScript I can easily get the URL using document obj as
      document.location.href or window.location.href

      Can i get the same in ScriptEngine ..??

      When i tried

      ScriptEngineManager factory = new ScriptEngineManager();
      ScriptEngine engine = factory.getEngineByName("JavaScript");
      s = (String)engine.eval("var urll = document.location.href; return urll)");

      it is giving
      javax.el.ELException: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "document" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1

      Any idea wat am i missing..
        • 1. Re: ScriptEngine to get the URL
          800282
          Vinothssn wrote:
          In JavaScript I can easily get the URL using document obj as
          document.location.href or window.location.href

          Can i get the same in ScriptEngine ..??

          When i tried

          ScriptEngineManager factory = new ScriptEngineManager();
          ScriptEngine engine = factory.getEngineByName("JavaScript");
          s = (String)engine.eval("var urll = document.location.href; return urll)");

          it is giving
          javax.el.ELException: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "document" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1

          Any idea wat am i missing..
          Err, I know jack about JavaScript, but when doing so in JS, you're actually ON a webpage so 'document' actually IS something then. When executing "var urll = document.location.href; return urll)" through Java like you are now doing, what did you expect to get in return?
          • 2. Re: ScriptEngine to get the URL
            793415
            [eval=document.location.href|http://pscode.org/jse.html?eval=document.location.href].
            sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: 
            "document" is not defined. (<Unknown source>#1) in 
            <Unknown source> at line number 1
            The JavaScript engine is very simple, and does not support the 'document' object even when happening in an applet. If this process is to happen in an applet, use getDocumentBase() for the page location, or declare MAYSCRIPT/SCRIPTABLE in the applet element to use (browser based) JS to retrieve the URL with parameters (which are lost to getDocumentBase()).

            If this is not supposed to be happening in an applet, then I would share the thoughts of the other replier.