Home > Web Front-end > JS Tutorial > body text

JavaScript static and dynamic_javascript skills

WBOY
Release: 2016-05-16 19:26:16
Original
1093 people have browsed it

During this time, I was building a website, and the space did not support ASP, so I picked up the JavaScript tutorial and looked at it to see if I could achieve dynamics in a static space. Of course, this dynamic is not real, so to speak. It's just a "pseudo-dynamic" :)
The most basic function of a dynamic page is in the form of news.asp?id=1, so I started working on this goal, and after working on it for a while, it actually achieved some results. ~The basic idea is: get the address of the current file from the browser's address bar, then extract the id from it, and finally use an inline frame to display related content. The following is the basic code

Copy code The code is as follows:

<script> <br>var str, len,pos,id,fn; ​​// Define some variables <br>str=top.window.location.href; // Get the natural file address <br>len=str.length; // Get the address length <br>pos =str.indexOf("?id=",0); // Get the starting address of "?id="<br>if(pos>0) // Determine whether "?id=" <br>{ <br> id=str.substring(pos 4,len); // Get ID <br> fn="<iframe src='news/" id ".htm'></iframe>" // Included Display relevant content in the embedded frame <br> document.write(fn); // Output <br>} <br>else <br>{ <br> document.writeln("Wrong parameter!"); // Does not exist ID <br>} <br></script>

In this way, you can make news pages and put them in the news directory, and then call news.htm?id=1 externally to view related News~~ Of course, the code here is not mature, for example, it does not determine whether the ID is a number, etc. This will be gradually improved in the future:)
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!