Welcome Guest, Not a member yet? Register   Sign In
Passing variable to external javascript file in uri
#4

[eluser]TheFuzzy0ne[/eluser]
It probably is possible, but I think it makes things too complicated. You could probably get the PHP parser to parse JavaScript files on request, and you could then take the arguments from the URI, and insert them into the JavaScript file, but that's extra server work for the sake of saving a line of HTML code.

Another idea might be to have your JavaScript grab the data from a cookie, but again, it just over-complicates things.

Oh and one more idea, which might not be quite so complicated, but does mess up your structure slightly, might be to have a controller method that returns the specified JavaScript file after it's been parsed. That way, you only need to request JavaScript files that need parsing via the controller, all other files come straight from your js subdirectory in your Web root.

Code:
class Get_js extends Controller
{

    function Get_js()
    {
        parent::Controller();
    }

    function file($file_name="")
    {
        # Grab parameters from URI, or session..
        # include the javascript file (but buffer the output).
        # Send the headers and file contents.
    }
}


Messages In This Thread
Passing variable to external javascript file in uri - by El Forum - 04-11-2009, 10:08 AM
Passing variable to external javascript file in uri - by El Forum - 04-11-2009, 10:14 AM
Passing variable to external javascript file in uri - by El Forum - 04-11-2009, 10:33 AM
Passing variable to external javascript file in uri - by El Forum - 04-11-2009, 10:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB