0

This is a link for an example of Edit source Code:

http://neokoenig.github.io/jQuery-gridmanager/demo/tinymce.html

the button which value is </>.

He get the code HTML even if he changes the content of the grid.

How to get the source code HTML using JavaScript or jQuery?

Thanks.

Dylan Wheeler
  • 6,928
  • 14
  • 56
  • 80
khalil _diouri
  • 791
  • 3
  • 12
  • 34

5 Answers5

2

you can use the html method with jquery, i.e for get the whole page html like this:

$( document ).ready(function() {
    console.log($("html").html());
})
lem2802
  • 1,152
  • 7
  • 18
  • this html() get code html after is genereted I need to get code html as I typed in my IDE – khalil _diouri Jul 19 '16 at 12:40
  • 2
    i'm trying to understand what you want to do. but i can't lol... please tell us what you want to do – lem2802 Jul 19 '16 at 12:42
  • I'm working with angular2 and there is some input wich I add in html code like this and when I get my code using method html() I dont get [name] as I typed in my IDE(intellij) – khalil _diouri Jul 19 '16 at 12:44
  • but do you see the input rendered in the document??? if yes use 'html();' into a document ready function – lem2802 Jul 19 '16 at 12:47
  • can you give an example for using html() into a document ready function – khalil _diouri Jul 19 '16 at 12:50
  • I get code html bu with the same problem the pronlem I think becomes from angular2 Apps – khalil _diouri Jul 19 '16 at 12:59
  • but do you see the input in the browser??? use the inspect element options in the browser and tell me what is inside... look at this question may be could help you: http://stackoverflow.com/questions/35072199/correct-way-to-use-libraries-like-jquery-jqueryui-inside-angular-2-component – lem2802 Jul 19 '16 at 13:14
  • I see it in inspect element it gives me the same result as html(); method for example [dropzones]="zone1" becomes ng-reflect-dropzones="zone1" – khalil _diouri Jul 19 '16 at 13:26
2

Using JavaScript

document.documentElement.outerHTML

More info

or

document.documentElement.innerHTML

More info

daan.desmedt
  • 3,752
  • 1
  • 19
  • 33
1

I'm not sure what you want to do exactly but if you want to get raw source code from jQuery you can use the following:

var html = $('element').html();

And with pure javascript from an id

var html = document.getElementById('id').innerHTML;

or from classname

var html = document.getElementsByClassName('class').innerHTML;

And to get the content of your example (which is an editor called tinymce) you can use the command tinymce.activeEditor.getContent(); or tinyMCE.get('myTextarea').getContent()


EDIT: If you want to listen for changes with jQuery and display to html dynamically you'd want to do something like this:

$('yourTextArea').keyup(function() {
    var html = $(this).val();
    $('yourElementToDisplayTheHTML').html(html);
});
Jonathan Nielsen
  • 1,442
  • 1
  • 17
  • 31
0

I've built a simple API, just use this:

<script src="https://cdn.jsdelivr.net/gh/Parking-Master/viewsource@latest/vs.js"></script>

In your JavaScript:

getSource('https://example.com/');
-2

in http response header, you can find "content-type" header. that header indicates how contents of page should be rendered. so, if you want to render page as plain text("source code", as you mentioned), just change that header like this -> "content-type : text/plain; charset=UTF-8"

if you can use ajax in jquery or javascript

use like this

$("button").click(function(){
$.ajax({url: "page_you_want.html", success: function(result){
    alert(result);
}});

});

전원표
  • 170
  • 1
  • 11