Asked by:
Edit HTML Page at Runtime in WinJS

Question
-
hello,
i want to upload a HTML in to my WinJS App. and show the content which can be modified and to be saved.
Wednesday, October 24, 2012 12:51 PM
All replies
-
Hi,
You could use Winjs.xhr to do that.
For example:
var feedItems = []; function loadBlogFeedsFromWebAsXML() { var feedUrl = "http://blogs.msdn.com/b/windowsstore/rss.aspx"; WinJS.xhr({ url: feedUrl }).then( function (result) { var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument(); xmlDoc.loadXml(result.responseText); var nodes = xmlDoc.selectNodes("//item"); var items = new Array(); nodes.forEach(function (val, idx, travObj) { var title = val.selectSingleNode("title").innerText; var description = val.selectSingleNode("description").innerText; var link = val.selectSingleNode("link").innerText; var newItem = { title: title, summary: description, uri: link }; items.push(newItem); }); DataUtils.feedItems = items; // Call other function which can use the DataUtils.feedItems to bind UI elements }, function (err) { } ); return DataUtils.feedItems; } WinJS.Namespace.define( "DataUtils", { feedItems: feedItems } );
#WinJS.xhr function
http://msdn.microsoft.com/en-us/library/windows/apps/br229787.aspx
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code FrameworkThursday, October 25, 2012 3:47 AM -
Dear Song Tian,
This above sample is used to read the XML File.
i want to read the HTML file and show into my page.
var UploadedFile = document.getElementById(FileUploaderClientId); if (UploadedFile != null) { var CurrentFile=UploadedFile.files[0]; if (CurrentFile) { var reader = new FileReader(); reader.onload = FileContent; reader.readAsText(CurrentFile); }
function FileContent(evt) { var Content = document.getElementById('Content'); Content.innerHTML = evt.target.result; }
By this way i will read the HTML File Data and shown in my page.
but, i any script is included in the HTML file means it will show an error.
please help me to Edit Uploaded HTML file through my page.
- Edited by PrabhuMuthusamy Friday, October 26, 2012 10:16 AM
Friday, October 26, 2012 10:15 AM -
have you tried using innerText instead of innerHTML?
innerHTML causes DOM parsing.
Sunday, October 28, 2012 12:56 AM -
ya i tried innerText also.
If i use innerText, it will show the source of the HTML page. but my requirement to show the HTML file as a Preview Mode and also provide option to edit HTML Page content.
Wednesday, October 31, 2012 4:42 AM