开发者

How to change all text of web page in javascript?

开发者 https://www.devze.com 2023-04-11 15:43 出处:网络
I want to change all of the text in the web page with JavaScript I want to make an application that\'s can change the text of an HTML page for replace correct text instead of wrong or incorre开发者_高

I want to change all of the text in the web page with JavaScript

I want to make an application that's can change the text of an HTML page for replace correct text instead of wrong or incorre开发者_高级运维ct text.

you think i want to make an app just like Google translator;)


I'm unclear on your question, but if you just want to replace the entire text of a page, just do

document.body.innerHTML = 'replacement HTML';

That won't affect the title, but you can change the title via

document.title = 'replacement plain text';

If you want to replace a web-page with text, then you can do

while (document.body.firstChild)
  document.body.removeChild(document.body.firstChild);
document.body.appendChild(document.createTextNode(myText));


If you want to keep all divs and layouts and want only to to change the text, you cannot change the innerhtml of the body. You must separately change the innerhtml of all the elements in the page. It's straightforward but tedious.

0

精彩评论

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

关注公众号