如何通过使其成为一行代码来最小化 HTML 代码?

发布于 2024-08-17 05:10:11 字数 410 浏览 1 评论 0原文

所以我制作了一个HTML、内联CSS和JS的网页。由于此页面将通过 JS 函数生成,因此

 opened.document.write();

我想将所有网页代码放入一行中,以便可以在前面提到的函数之一中使用,而不是为每个新行重复相同的函数。我无法手动执行此操作,因为该页面包含太多代码行。

有没有一种快速、干净的方法来做到这一点?

注意:我使用一些程序一键将所有“替换为\”,所以我希望能够将所有(Enter)替换为(Backspace)或类似的事情。


详细说明

我想在用户单击按钮时生成整个页面,该按钮将调用 JS 函数,该函数将生成一个新页面并使用前面提到的函数编写它。

So I have made a web page of HTML, Inline CSS and JS. Since this page will be produced through JS function

 opened.document.write();

I would like to put all the web page code into one line that can be taken in one of the previously mention function instead of repeating the same function for every new line. I can't affors doing this manually,because the page contains too many lines of code.

Is there a fast and clean way to do this?

Notice: I used SOME PROGRAM to replace all " with \" by one click, so I hope there is away to replace all the(Enter)s with (Backspace) or something like that.


Elaboration

I want to produce the whole page when the user click on a button which will call a JS function which will produce a new page and write it using the previously mentioned function.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱给你人给你 2024-08-24 05:10:11

嗯,答案是“是”,但这有点干扰你正在做的事情。

我不知道是否可以在 Word 中替换特殊字符,但在大多数文本编辑器(Textpad、Notepad++)中,您可以通过“正则表达式”进行替换,这样您就可以编写“\r\n”以将所有换行符替换为任何内容你希望。

但我必须说,我想知道你为什么要这样写这份文件。你能详细说明一下吗?

Hmm, well the answer is "Yes", but it's slightly disturbing what you are doing.

I don't know if you can replace special characters in Word, but in most text editors (Textpad, Notepad++) you can replace via a 'regex' so you can write "\r\n" to replace all instances of newlines with whatever you wish.

I must say, though, that I wonder why you wish to write out the document like that. Can you elaborate?

jJeQQOZ5 2024-08-24 05:10:11

您可以使用带有正则表达式的在线文本编辑器,粘贴您的代码并修复一些正则表达式以替换 \r 和 \ n 有空格或没有空格。我不知道正则表达式,所以你必须自己做或询问。

You could use an online text editor with regex, paste your code in and fix up some regex to replace \r and \n with a whitespace or no spaces. I don't know regex so you'll have to do it or ask for it yourself.

·深蓝 2024-08-24 05:10:11

更改由 Javascript 生成的 HTML 页面是一个非常糟糕的主意。您正在使整个网站对搜索引擎、关闭 JavaScript 的用户以及使用屏幕阅读器的用户几乎不可见,这样做有什么好处?节省几百字节?使用 gzip 压缩和适当的缓存控制设置您的网络服务器,并保持源代码不变。

Changing your HTML pages to be generated by Javascript is a Very Bad Idea. You're making your entire website virtually invisible to Search Engines, users with javascript off, and those using screen readers, and for what benefit? Saving a couple of hundred bytes? Set up your webserver with gzip compression and proper cache control and leave the source as is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文