使用嵌入的 javascript(或其他东西)编辑另一个 html 文档?

发布于 2024-11-30 15:22:31 字数 451 浏览 0 评论 0原文

我最近设计了学校网站的主页。网站的其余部分是在 WordPress 中完成的,其他人很容易编辑,但主页却不是。我认为制作一个网站的管理页面会很酷,它允许您通过单击按钮来设置各种主页属性(例如背景颜色)。

我愿意让管理页面直接编辑主页,或者编辑中间 xml(或其他)文档,然后更改主页以从那里提取变量。然而,我想做最少的工作,宁愿不要用 xml 编写整个主页,而是用 xls 将其更改为 html。 (我的主页已经足够复杂了)。当我在网上查看时,这主要是针对这种情况的所有建议。

我可能会大胆猜测 php 拥有这个问题的答案,但我以前从未使用过 php 所以我真的不知道。

我精通 JavaScript,非常熟悉 html 和 css,但对 xml/xls/ajax/php 几乎不熟悉,所以如果您的答案使用了这些,请解释一下。 :)

(顺便说一句,理想情况下这一切都在服务器上完成,无需上传/下载。)

谢谢

I recently designed the homepage of my school's website. The rest of the site is done in WordPress, and is easy for other people to edit, but the homepage is not. I thought it would be cool to make an admin page of the website which would allow you to set various homepage attributes (eg background color) with the click of a button.

I would be open to either having the admin page edit the homepage directly, or edit an intermediary xml (or other) doc and then change the homepage to pull variables from there. However, I want to do the minimum amount of work and would rather NOT write the whole homepage in xml and change it to html with xls. (my homepage is complex enough as it is). When I looked online, this was mostly all that was suggested for a situation like this.

I might venture to guess that php holds the answer to this, but I have never used php before so I don't really know.

I am competent in JavaScript and very familiar with html and css but only barely familiar with xml/xls/ajax/php, so if your answer uses those, please explain. :)

(by the way this would ideally all be done on the server without upload/downloads.)

Thanks

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

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

发布评论

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

评论(2

温柔戏命师 2024-12-07 15:22:31

假设属性主要是视觉的,我会说为此使用外部样式表。您可以使用 PHP 根据管理页面上表单的输入值创建样式表。该表单允许用户选择背景颜色、文本颜色和各种其他属性。点击提交后,表单将调用“change.php”。在“change.php”文件中,根据您的选择,使用 POST 或 GET,您可以获取所有表单数据并以编程方式编写样式表。通过使用 PHP 文本文件方法打开服务器上的现有样式表并覆盖所有文本,然后保存文件来保存样式表。更改将立即生效,无需更改主页上的任何代码。为了获得良好的效果,您可以从“change.php”文件本身重定向到“新”主页,以便管理员可以看到更改的结果。

我意识到我只介绍了高层次的细节,但是让您详细了解我所说的所有内容将使这篇文章成为一篇文章,这将花费我几天的时间来写。然而,就 PHP 的用途而言,学习 PHP 并不那么难。快速进行 Google 搜索,这是我发现的第一件事,它解释了如何使用 PHP 编辑文本文件: http://www.webmasterworld.com/forum88/1965.htm

我假设您知道如何创建样式表,以及如何使用 HTML 创建表单,因为您提到您非常了解对这两个都熟悉。也许您以前没有将表单与 PHP 集成,所以这里有一个提示。您表单的“action”属性将为“change.php”,表单的“method”属性将为 POST 或 GET,具体取决于您的选择。希望这有帮助!

Assuming the attributes are mostly visual, I'd say use an external style sheet for this. You can use PHP to create the style sheet based on input values from a form on your admin page. The form would allow the user to select the background color, text color, and various other attributes. Upon hitting submit, the form will call 'change.php'. In the 'change.php' file, using either POST or GET, depending on which you choose, you can get all the form data and programmatically write a style sheet. Save the style sheet by opening the existing style sheet on the server using PHP text file methods and over-writing all the text, and then saving the file. The changes will go into effect immediately, without having to change any code on the home page. For a nice effect, you could redirect to the 'new' home page from the 'change.php' file itself, so admins can see the results of their change.

I realize I only covered the high level details, but walking you through all that I've said in detail would make this an article, which would take me a couple days to write. However, PHP is not all that hard to learn for what you are using it for. And doing a quick Google search, here's the first thing I found that explains how to use PHP to edit text files: http://www.webmasterworld.com/forum88/1965.htm

I'm assuming you know how to create a style sheet, and how to create a form using HTML, since you mentioned you are very familiar with both of those. Perhaps you haven't integrated your forms with PHP before, so here's a hint. Your form's 'action' attribute will be 'change.php' and your form's 'method' attribute will be either POST or GET depending on which you choose. Hope this helps!

花之痕靓丽 2024-12-07 15:22:31

在这里我知道有一种简单的方法可以让访问者编辑您的网站。

将此功能添加到您的网页中。
javascript:document.body.contentEditable='true'; document.designMode='on';无效 0

Here i know there is an easy way to allow visitors to edit your website .

Add this function to your webpage .
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

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