开发者

Where is the Java Script object stored on disk?

开发者 https://www.devze.com 2023-02-27 02:06 出处:网络
I am new to Java Script. This HTML and Java Script code transliterates an English word to Bengali, using the Google Transliteration API. I load this file in a browser and the result appears on the pag

I am new to Java Script. This HTML and Java Script code transliterates an English word to Bengali, using the Google Transliteration API. I load this file in a browser and the result appears on the page (just the Bengali word).

Viewing the page source in Firefox shows an empty <div id="transliteration"></div> tag, as it was in the HTML code I loaded.

But using Firebug, I can clearly see that the Bengali word is indeed within this tag.

Again, using HttpFox I can see the result object received by the script from Google.

Questions are;

Why is the page source in Firefox devoid of the result, even though Firefox has rendered the result and I can see it right there ?

Where on disk are these programs (Firebug and HttpFox) looking for the result object ?

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="https://www.goog开发者_如何转开发le.com/jsapi?key=MY_KEY">
    </script>
    <script type="text/javascript">

    google.load("language", "1");

    function initialize() {
      google.language.transliterate(["Mohona"], "en", "bn", function(**result**) {
        if (!result.error) {
          var container = document.getElementById("transliteration");
          if (result.transliterations && result.transliterations.length > 0 &&
            result.transliterations[0].transliteratedWords.length > 0) {
            container.innerHTML = result.transliterations[0].transliteratedWords[0];
          }
        }
      });
    }

    google.setOnLoadCallback(initialize);

    </script>
  </head>
  <body>
    <div id="transliteration"></div>
  </body>
</html> 

The result in the div tags (Firebug):

Where is the Java Script object stored on disk?

The result object (HttpFox). Sorry for the poor quality image. The last line of black text is the entire result object (not the orange bar).

Where is the Java Script object stored on disk?


View is Source shows the HTML as originally loaded. Firebug is showing you the DOM of the page in HTML form, after the page's JavaScript has run and modified the DOM.


Javascript manipulates the DOM in-memory.

So there is no representation of the altered DOM anywhere on disk.

View-source will only display the data it received from the server.


To access it from javascript you need to do

var html = document.getElementsByTagName('html')[0].innerHTML;
alert(html); // just to see it

but to write it to a file you will need more than that because javascript can not access the filesystem (for security reasons)

For manual saving, you can just put the contents of the html variable in a <textarea> and copy/paste in a file.

0

精彩评论

暂无评论...
验证码 换一张
取 消