How to extract part of the coding of an HTML webpage to an external file?
My HTML-written website has several pages with similar codings written for the appearance and functioning of the top navigation bar. How can I extract that part of the codes by Javascript so that when I want to make changes to the top navigation bar, I can just change that external file for once and don't need to make the same changes repeatedly for every pages. And also can I preview these Javascript-webpages in my own computer before publishing it to the webhosting computer. Thanks a lot in advance.
Thank you for the iframe advice. But I've heard that frame is not good for seach engines, is it? If frame is really not good for search engines, is there other way to achieve my end?
Public Comments
- Actually you don't need javascript for this. Define an iframe tag with the source as the html page with the navigation bar. In fact, if you have a dynamic site instead of static pages, you can build the navigation bit from a different page template, and receive the same results. Edit: The longer more difficult option is that you use javascript to provide the innerHTML of a div tag. Or you put a div tag at the top of your page. Then you load the html file as an xml file and parse it to the location that you want and then write a small javascript loop to go through all the tags as elements and insert them as children of the said div tag. You should be able to figure it out. If you have any problems, PM me.
- Yes, there are other ways. As they are reputed to say in AOL-land, "you have mail." The sample is kind o' big to insert and has some personal info, I prefer not to post publicly here. Should be all you need.
- Is the webhosting PHP, JSP, ASP.NET? Or even more traditional static SSI and CGI? Those have mechanisms for external files the simplest type would fill your need, in one simple line no less. Otherwise importing back via other methods are doable just not simple. As far as extracting parts to external file for the use of either above two method can be done programmatically only if your HTML is xHTML (XML conformed) via some simple XSLT in variation of an "identity" template that dump things you don't want, accessing XSLT via Java or any modern languages or special reader software.
Powered by Yahoo! Answers