开发者

use embedded javascript (or something else) edit another html doc?

开发者 https://www.devze.com 2023-03-29 15:28 出处:网络
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

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.)

开发者_StackOverflow社区

Thanks


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!


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

0

精彩评论

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