Dynamic _javascript techniques for JavaScript static

Source: Internet
Author: User
This time because to do a website, and the space does not support ASP, so took up the JavaScript tutorial looked, see can be in the static space to achieve dynamic, of course, this dynamic is not the real sense of the, can be said to be just a "pseudo dynamic":
The most basic features of dynamic pages, is news.asp?id=1 such form, so I take this target to start, get a while really some effect ~ The basic idea is: get the address of the current file from the address bar of the browser, then extract the ID from it, and finally use the inline frame to display the relevant content. Here's the basic code
Copy Code code as follows:

<script>
var str,len,pos,id,fn; Define some variables
Str=top.window.location.href; Get the address of the course file
Len=str.length; Get address length
Pos=str.indexof ("? id=", 0); Get start address for "? id="
if (pos>0)//To determine if there is a "? id="
{
Id=str.substring (Pos+4,len); Get ID
fn= "<iframe src= ' news/" + ID + ". htm ' ></iframe>"//inline frame display related content
document.write (FN); Output
}
Else
{
Document.writeln ("wrong argument!")  "); ID not present
}
</script>

In this way, you can put the news into a page in the information directory, and then call News.htm?id=1 on the outside can come to see the relevant news ~ ~ Of course, the code here is not mature, such as no judgment ID is the number, etc., such as later to gradually improve:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.