当前位置: 首页 > 网络学院 > 设计教程 > 设计理念 > 利用JavaScript更新网站

设计理念
什么是XHTML?
启发设计灵感
网站设计的新视角
从最优化角度来设计你的网站
脱离Google生存
logo的类型
Flash的弊端
避免使用JavaScript动态导航条的7大理由
正确使用“留白”属性
商务图形设计
如何使用“哇元素”
提高网站的可访问性
让你步入专家领域
“一页站点”的概念
高级网页设计原则
接近你的客户
创建网站的黄金法则
3条帮助你成功创建“会员制营销”的方法
重新改造你的主页
避免图形文件过量

设计理念 中的 利用JavaScript更新网站


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 1808 ::
收藏到网摘: n/a

Use_JavaScript_To_Dynamically_Update_Your_WebsiteIf you've been on the Internet for a while, you've probably seen numerous examples of JavaScript use. JavaScript is a powerful scripting language used to create special effects on your website, but did you know it can also be used as a very powerful web design tool?

你可能注意到很多网站运用JavaScript,的确,JavaScript是一种能够创造特殊效果的脚本语言,但你是否知道它可以作为一种强有力的网站设计工具呢?

Have you ever joined a new affiliate program or created a new publication that you wanted to add to your existing navigational set up, but dreaded having to manually add the links to every page on your site?

你是否希望加入一种新程序,或者希望在原导航系统中添加出版系统,而需要手工改动每一张网页的链接呢?

You can use JavaScript to enable you to dynamically update every page on your website with just one file. This technique is the same technology used by numerous syndication services on the Internet. It enables them to deliver dynamically updated content to every website in their program.

你可以利用JavaScript程序自动改变网站的每张网页。这项技术被网上的许多企业运用,帮助网站更新内容。

Before we begin, if you'd like to see an example of a navigational system that is dynamically displayed, visit Web-source.net. This website has over one thousand pages and each and every one of them displays its navigational system using JavaScript. If I want to add an additional link, I simply update one file and every page on the site is automatically updated.


开始介绍之前,你可以登录Web-source.net,浏览自动呈现的导航系统。这个网站包含一千多张网页,利用JavaScript每一张网页都可以呈现导航系统。如果希望添加其它链接,你只需要更新一个文件,这样所有网页都会自动更新。

The first step in setting up your JavaScript feed is to create the file that will contain your content. To do this, open a text editor such as NotePad and simply copy and paste your existing navigational setup into a new page. There is no need to begin the page with <HTML><HEAD>, etc. as you are only creating the feed for one section of your existing web page which already has those tags.

利用 JavaScript更新内容的第一步就是要创建一个包含网站内容的文件。创建文件时,打开类似于NotePad 的文本编辑器,把现存导航系统复制,然后粘贴到新建网页中。你没有必要首先修改<HTML><HEAD>等,因为你仅仅是修改现有网页,现有网页已经包含这些标签。

Once you've created your new page containing your navigational HTML, you'll now need to add some additional JavaScript coding to each line of your HTML. The first line of your new file will look like this: <!--

创建包含导航HTML的新网页以后,你需要在HTML内容中增加其它JavaScript编码。新文件的第一行应该这样:<!--

The next line will begin with "document.writeIn('" and end with "');" (without the quotes). Your first line of HTML will be placed between the beginning and ending coding. For every line of your original coding, you'll need to add the above-mentioned codes before and after. Note: Make sure you don't add any extra spaces, including at the end of each line, as JavaScript is very sensitive. Your new file will end with //--> on the last line.

下一行以"document.writeIn('"开始,以"');"结束(没有引号)。首行HTML编码放置在开始与结束编码之间。每一行原始编码,都需要在开始与结束前,添加上述编码。请注意:避免添加任何其它空格,包括每一行的结尾,因为JavaScript很敏感,并且新文件要以//-->结束。

Here's how your code might look:


编码形式如下:

<!-- document.writeln('<TABLE BORDER="0" ALIGN="Center">'); document.writeln('<TR>'); document.writeln('<TD>'); document.writeln('Your table content'); document.writeln('</TD>'); document.writeln('</TR>'); document.writeln('</TABLE>'); //-->

Each backslash () should be preceded with another backslash.

每一个()符号放置在另一个反斜线符号之前。

Example:

例如:

Each apostrophe (') should be preceded with a backslash.

每一个省略符号(')放置在反斜线符号之前。

Example: '
 
例如:'

You can include most HTML and JavaScript coding however, you cannot include JavaScript that must access another file to run.

你可以包含大多数HTML或者JavaScript编码,然而,却不能包含推进文件运行的JavaScript

After you've created your content and added the special JavaScript coding, you'll need to save your new file. Try to select a name that reflects your file such as navigate.js and make sure your filename is no longer than eight letters. Next, you'll need to create a new directory on your server where you store your HTML files. Name this directory "content" (without the quotes) and upload your new .js file in ASCII.

创建内容,增加特定JavaScript编码以后,你需要保存新文件。尽量选择一个可以反映文件性质的名称(例如:navigate.js),并且保证文件名不超过8个字母。其次,你必须在储存HTML的服务器中创建新目录。目录命名为“content”(没有引号),然后利用ASCII模式将.js文件上传。

Here's where the magic occurs... Place the following code in your HTML pages where you would like your navigate.js content to be displayed. Make sure you change the URL and direct it to your new .js file. The following code must be displayed exactly as it appears. Make sure there are no spaces after the first line of code.

这里显得有点不可思议。把以下编码放置到navigate.js文件内容将会呈现的网页中,确保可改变URL,使其与新.js文件链接。以下代码必须原样重现,第一行编码后不可以出现空格。
<SCRIPT language="JavaScript" src="http://www.yourdomain.com/content/yourfile.js"> </SCRIPT>

If you've followed the above steps correctly, your navigational system should now be displaying on your web page. If you are receiving a script error message, most of the time, it's due to an extra space at the end of a line or an extra or missing character. Make sure you go over your code very carefully. Once you've created your content feed and it is displaying your content, updating your file will be simple.

如果正确遵循以上步骤,导航系统应该正在呈现网页,如果收到原本错误信息,可能是末尾行出现了空格或者其它内容,也有可能是遗漏了其它内容。一旦创建目录之后,服务器就会呈现内容,上传文件就会很简单。

Use_JavaScript_To_Dynamically_Update_Your_Website

If you'd rather not have to code the JavaScript yourself, I use a great script called, Master Syndicator which will code your content for you. I highly recommend it. Web-source.net

如果不希望利用JavaScript,我推荐你使用Master Syndicator,这个程序会为你自己编辑目录,你可以登录Web-source.net,查看相关内容。

Using JavaScript to display your navigational set up can not only enable you to instantly update the content on every page of your website, but can also save you hours of valuable time.

运用JavaScript不仅可以帮助你立即更新网页内容,还可以节省你宝贵的时间。

评论 (0) All

登陆 | 还没注册?