Basically, I have an html page and I want to create a separate javascript file that reads all of the markup between the tags into a javascript string. Is there a way to do that?
EDIT
Okay, so, to elaborate a little more...
In my tpl.php file, I basically have these lines js snippet:
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">var text = '<div id="open">test text</div>';</script>
<script type="text/javascript" src="/js/mypag开发者_开发问答e.js"></script>
Then, in mypage.js, I have this:
$(document).ready(function() {
var content = text;
alert(content);
});
And this accurately displays "test text" in an alert window, but I'm looking for the variable to actually look like var text, so that it reads:
var content = '<div id="open">test text</div>';
If I understand you correctly, you want to read the content of the HTML tag (<html>...</html>
) with JavaScript?
Easy to do:
var str = document.getElementsByTagName('body')[0].innerHTML;
EDIT: Fixed syntax error.
EDIT2: Used body
instead of html
tag.
精彩评论