www.webdeveloper.com
Results 1 to 5 of 5

Thread: How can I get HTML code generated by Javascript

  1. #1
    Join Date
    Dec 2009
    Location
    China
    Posts
    3

    Unhappy How can I get HTML code generated by Javascript

    Hi all:
    I've got a problem now ,for how can I get HTML code generated by Javascript? for example:
    HTML Code:
    <script src="contentjs/portal/1120.js" type='text/javascript'></script> 
    <script type='text/javascript'> 
    if("undefined" != typeof _article_1120)
    for(i=0;i<12;i++)
    {
    	var dd=_article_1120[i];
    	if("undefined" == typeof dd){
    		break;
    	}
    	
    	var title = dd['title'];
    	if(title.length > 16){
    		title = title.substring(0,16)+'...';
    	}
    	document.write("<li><a href='"+dd['url']+"' target='_blank' >"+title);
    	document.write("</a></li>");
    }
    </script> 
    Now,I want to get HTML code generated by "document.write();"
    Any ideas?

    thanks in advance!

    lee

  2. #2
    Join Date
    Dec 2009
    Location
    China
    Posts
    3
    Just like firebugs ,it can print the source html code..

  3. #3
    Join Date
    Feb 2006
    Posts
    2,927
    build up a string inside the loop and put a single document.write(string) after.
    Then read, pass, or handle the string.

    If you want to see how it was rendered by the browser, check the innerHTML of the body before and after the write,
    or if you are writing all to one parent element, check its innerHTML.
    Last edited by mrhoo; 12-10-2009 at 11:03 PM.

  4. #4
    Join Date
    Dec 2009
    Location
    China
    Posts
    3
    hi mrhoo , I can do what you've said only when I loading the body.But is there any way I can get the innerHTML when it completely initialized?
    Since I knew,the DOM can not be reversed.

    thanks.

    lee

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787

    easy way

    Quote Originally Posted by leekooqi View Post
    hi mrhoo , I can do what you've said only when I loading the body.But is there any way I can get the innerHTML when it completely initialized?
    Since I knew,the DOM can not be reversed.

    thanks.

    lee
    in firefox, left-click the page background, press [ctrl]+[a], right-click the page background, and select "view selection source".

    works every time...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles