Author: Lati Matata email : mlati@yahoo.com Date : 21/07/2000 Tired of having to repeat the same Client-side support script's(JavaScript) for different pages?. This ASP Subroutine takes in the name of the function(s) as an array e.g
Dim func_arr(1) func_arr(0)="function foo()" func_arr(1)="function foo1()" and the name of the central file that contains all the support javascript functions that you reuse (relative to the current file) e.g
dim RelativeFilePath RelativeFilePath = "includes/client_script.asp"
You can then call the function within the script tags of the page your wish to insert the javascript function.
<!--#include virtual="/script.asp"--> ..... <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript> <!-- <% Dim func_arr(1),RelativeFilePath func_arr(0)="function foo()" func_arr(1)="function foo1()" RelativeFilePath = "includes/client_script.asp" call Print_Client_Script(func_arr,"includes/Client_Script.asp") %> //--> </SCRIPT> ......
IMPORTANT!!. 1. The JavaScript function MUST be well formed!--would work "as is"...if manually inserted. 2. The client script file size should be not more than 64k for optimal performance
I'll be happy to take any questions/comments, dont expect an immediate reply though!.
///the subroutine///////script.asp///begin////////////////////////////////////
CONST MAX_ITERATIONS = 65536 '64K
public sub Print_Client_Script(func_Name_arr,File_Name)
'func_Name_arr ---array of names of the functions to print out 'File_Name ---location of the file containing the function name(relative)
dim fileObj,file_path,fileStream,i,code_str,ForReading dim func_Start_pos,iControl,Func_length,Func_End_pos ForReading = 1 Set fileObj = CreateObject("Scripting.FileSystemObject") file_path = server.MapPath(File_Name) 'complete physical path to client script file if (fileObj.FileExists(file_path)) and isarray(func_Name_arr) = true then 'checking for file existence! Set fileStream = fileObj.OpenTextFile(file_path,ForReading) code_str = fileStream.ReadAll() 'reads the contents into one long string and then closes it 'thats the reason for the limit on file size fileStream.Close() for i = 0 to Ubound(func_Name_arr) 'iterate through list of functions to search for '(assumption the cilent script page has many other functions) func_Start_pos = instr(1,code_str,trim(func_name_arr(i)),1) 'look for the function in the string if func_Start_pos <> 0 or func_start_pos <> null then 'function name has been found Func_End_pos = func_Start_pos 'initialise the various controls iControl = 0 Func_Length = 0 do if mid(code_str,Func_End_Pos,1) = chr(123) then 'looking for opening braces--"{" iControl = iControl + 1 elseif mid(code_str,Func_End_Pos,1)=chr(125) then 'looking for closing brace--"}" iControl =iControl - 1 if iControl = 0 then 'the iControl has go up then back down to zero(a full function!!) exit do end if end if Func_End_Pos = Func_End_Pos + 1 'move to the next character loop while true AND Func_End_pos < MAX_ITERATIONS 'max_iterations..just incase..dont want to hung the server! Func_Length = Func_End_Pos - func_Start_pos + 1 'add one to include the closing brace Response.Write mid(code_str,Func_Start_pos,Func_length)&chr(13) 'right out the whole function string else 'ERROR the function has not been found! end if next else 'ERROR the file does not exist end if Set fileObj = nothing end sub
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
| | | | Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
| | | | Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
| | | | IBM Enterprise Modernization solutions help organizations evolve core IT systems towards modern architectures and technologies—reducing the burden of maintenance and freeing up resources to develop new business requirements and capabilities. With the IBM Enterprise Modernization Sandbox for System z you can evaluate IBM Enterprise Modernization solutions focused on five key areas: Assets, Architectures, Skills, Processes and Infrastructures, and Investment. Each solution is based upon real customer experiences and offers a proven path to get you started with your modernization projects. FREE! Go There Now!
| | | | Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly. FREE! Go There Now!
| | | | The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |