I've got a page X that is supposed to have hyperlinks to pages A, B, and C if certain conditions are met. What I'm hoping to do is (on the server as the page is being built) is prune out hyperlinks that don't meet my conditions. The way I would like this to be structured is that in the Javascript开发者_高级运维 function that is building the HTML for the links on X, eval a function that exists in A, B, and C where a true/false is returned which tells me whether or not to include the link.
I've written it so far so that X dynamically pieces together the name of the appropriate function to call in A, B, and C based off of their names and uses eval. The problem is that eval doesn't seem to know where the functions are located.
Since this is server-side, I don't believe that I can use the tag because I think that's for client-side code. I don't want to use the at the top because I want X to be loosely coupled with A, B, and C.
This is Javascript in ASP pages running on IIS.
Any suggestions as to how I can make the eval locate the function on the server is appreciated.
mj
[edit]
function shouldLink(filename)
{
filename = "a.asp";
var splits = filename.split(".");
var file = splits[0].toUpperCase() + "_ShouldLink()"; // A_ShouldLink() function name built here
var exec = "<!--#include virtual=\"a.asp\" -->";
exec += "eval( " + file + " );";
try{
return eval( exec );
} catch( err ){
}
return true;
}
Basically at the eval here I want the function named A_ShouldLink() to be called (which resides in a.asp).
I may be wrong but I don't think you can use include files in this manner. I have never seen include files dynamically added this way.
Try
function shouldLink(filename)
{
filename = "a.asp";
var splits = filename.split(".");
var file = splits[0].toUpperCase() + "_ShouldLink()"; // A_ShouldLink() function name built here
Server.Execute(fliename)
var exec = "eval( " + file + " );";
try{
return eval( exec );
} catch( err ){
}
return true;
}
You will obviously need to be careful with the path for your file name.
I used this article for inspiration
I don't quite understand what you want to do, but if you are naming functions based on dynamic data, it seems you could step back and rewrite the functions to work dynamically through parameters, etc. Any chance you can post some code?
精彩评论