Ni Le
Ni Le

Reputation: 199

Getting variable from function

Is there a way for me to get the file url from this function without changing the javascript and without running the function?

  jwplayer('jsCmgPlayer').setup({
    flashplayer: 'http://website.com/player.swf',
    file: 'http://website.com/0015980.mp3',
    autostart: true,
 'skin': 'http://www.website.com/skin.xml',
 'controlbar': 'bottom',
    height: 28,
    width: 620
  });

I want to get http://website.com/0015980.mp3 as a separate variable.

Upvotes: 0

Views: 69

Answers (3)

Asciiom
Asciiom

Reputation: 9975

The javascript you provide is running the function already. Since you are calling the setup code and you provide the arguments you can do this:

// create the arguments object
var setupArgs = {
    flashplayer: 'http://website.com/player.swf',
    file: 'http://website.com/0015980.mp3',
    autostart: true,
    'skin': 'http://www.website.com/skin.xml',
    'controlbar': 'bottom',
    height: 28,
    width: 620
}

// setup the plugin
jwplayer('jsCmgPlayer').setup(setupArgs);

Now you can use the arguments however you want, to access that url:

// use the arguments object for other things
setupArgs.file;

Upvotes: 0

acme
acme

Reputation: 14856

It's not possible. If you don't run the function you can't access the property over the plugins API because it's never set nor can you access it from an outer scope in your JavaScript code. The argument hash is not visible outside of this function.

Upvotes: 1

Bergi
Bergi

Reputation: 665546

No. If the function is not run, the object containing the url can't be accessed. You only could try to get the function's source code as a string, and dig around in it e.g. with a regular expression to match that object literal.

Upvotes: 0

Related Questions