Maxthon provides various plugin commands to improve the capability of Script plugins. These plugin commands can be run through the window.external object. Some plugin commands requires a Security ID generated by Maxthon to be run.
How to obtain the Security ID
1. Script button plugins can use "%max_security_id" for the Security ID
2. Script sidebar plugins and HTML button plugins have to load "max.src", a script generated by Maxthon. Then "max_security_id" can be used。
<script src=max.src></script>
Reference for Maxthon Plugin Commands
Unless specified otherwise, the following plugin commands are applicable for both Maxthon 2.0 and Maxthon 1.X。
1. max_version - return Maxthon's version number
Example:
alert(external.max_version);
2. max_language_id - return Maxthon's language ID
Example:
alert(external.max_language_id);
Note: Maxthon 2.0 and Maxthon 1.X have different language ID format
3. tab_count - return the number of tabs opened by Maxthon
Example:
alert(external.tab_count);
4. cur_sel - return the index of Maxthon's current tab
Example:
alert(external.cur_sel);
5. m2_plugin_folder( security_id , plugin_name ) - return the folder path of the specified plugin
Example:
alert(external.m2_plugin_folder( %max_security_id , 'ViewSource!'));
6. m2_run_cmd( security_id , command_id ) - run the specified command ID
Example:
external. m2_run_cmd( %max_security_id , 32772 ));
Note: Maxthon 2.0 and Maxthon 1.X have different command ID. Command ID can be found in Maxthon's language file.
7. get_tab( security_id , tab_index ) - return the window object of the specifed tab
Example:
var oWin=external.get_tab(%max_security_id, 0);
alert(oWin.document.URL);
8. activate_tab( security_id , tab_index ) - activate the specified tab
Example:
external.activate_tab(%max_security_id, 0);
9. close_tab( security_id , tab_index ) - close the specified tab
Example:
external.close_tab(%max_security_id, 0);
10. readFile( security_id, plugin_name, file_name) - read the content of specified text file
Example:
var sText=external.readFile(%max_security_id, 'ViewPage', 'readme.txt');
alert(sText);
11. writeFile( security_id, plugin_name, file_name, content ) - write content to the specific text file
Example:
external.writeFile(%max_security_id, 'ViewPage', 'test.txt', 'This is the file content');
12. m2_readIni( security_id, plugin_name , file_name , section_name , key , default_value) - read data from specific INI file
Example:
var sDownloadTool=external.m2_readIni(%max_security_id, 'ViewPage', 'plugin.ini', 'Settings', 'Tool', );
alert(sDownloadTool);
13. m2_writeIni( security_id , plugin_name , file_name , section_name , key , value ) - write data to specific INI file
Example:
external.m2_writeIni(%max_security_id, 'ViewPage', 'test.ini', 'Config', 'height', '100px');
14. max_modelessDialog( security_id , url , option , attr , window ) - returns a modeless web page dialog
Example:
var oDialog= external.max_modelessDialog( %max_security_id , 'blank.html', window , , window );
var oDoc=oDialog.document;
oDoc.write('Testing');
oDoc.close();
15. max_activex(security_id ,program_id) - return specified ActiveX object
Example:
var oWSH=external.max_activex(%max_security_id, 'WScript.Shell');
oWSH.run('notepad.exe');
16. m2_search_text(security_id) - return the text in search bar
Example:
alert(m2_search_text(%max_security_id));
17. max_callback(event_name) - a function which is run when certain Maxthon events happen (for HTML button plugins and Script sidebar plugins)
HTML button plugins and Script sidebar plugins can implement the max_callback function for reacting to certain Maxthon browser events like switching to a different tab.
Example:
function max_callback(x){
if(x=='tab_change') alert('Current tab is changed.');
}
By checking the parameter of the max_callback function, plugin can get the following browser events:
HTML button plugins
tab_change – after the current tab is switched
document_Complete - after the current tab is fully loaded
self_destroy - when the html is unloaded, usually when Maxthon exits
Script sidebar plugins
sidebar_tab_change - after the current tab is switched
sidebar_activate - when the sidebar plugin is activated
sidebar_deactivate - when the sidebar plugin is deactivated
sidebar_unload - when the sidebar plugin is unloaded (Maxthon is closed)
18. max_getObj (for Maxthon 2.0 only) - return various Maxthon objects, including:
Info - general information about Maxthon
Adhunter – about Ad Hunter
FavManager – about Favorites
RssManager – about RSS
PluginManager - about Plugins, for Maxthon 2.0.5 or later
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
Info Object supports the following property and method:
Property:
fileProxy - read-only, returns the path of the current user's proxy configuration document.
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
alert(oInfo.fileProxy);
folderUser - read-only, returns the path of the profile folder of the current user
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
alert(oInfo. folderUser);
Method:
getFolderPluginData(plugin_name) - obtain the path of plugin data storage folder for the current user and the plugin
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
alert(oInfo.getFolderPluginData('ViewSource!'));
AdHunter object support the following method:
Method:
reloadFilter(filter_name) – reload the specified Maxthon filter (currently content filter only) after modifying the relevant filter
Example:
var oAdHunter=external.max_getObj(%max_security_id, 'AdHunter');
oAdHunter.reloadFilter('content');
enableFilter(filter_name, bEnable) – enable or disable Maxthon's 'content' or 'popup' filter
Example:
var oAdHunter=external.max_getObj(%max_security_id, 'AdHunter');
oAdHunter.enableFilter ('content', false);
PluginManager object support the following method:
getPluginFolder - return Maxthon main plugin folder path
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
alert(oPluginManager.getPluginFolder)
getCount - return the number of all installed plugins, both enabled and disabled
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
alert(oPluginManager.getCount)
getList - return a list which contains information like name, author etc of all plugins
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
alert(oPluginManager.getList)
getPlugin(Index) - Index is a number, return the corresponding plugin object
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
var oPlugin=oPluginManager.getPlugin(0);
The plugin object returned from getPlugin(Index) supports the following property and method:
Property:
title - read only, return plugin name
Example:
alert(oPlugin.title);
folderName - read only, return plugin's folder name
Example:
alert(oPlugin.folderName);
fullPath - read only, return plugin folder's full path
Example:
alert(oPlugin.fullPath);
enable - read/write, return or set if the plugin is enabled
Example:
oPlugin.enable=false;
alert(oPlugin.enable);
oPlugin.enable=true;
alert(oPlugin.enable);
startAfterPageDone - read/write, return or set if the plugin is auto started
Example:
oPlugin.startAfterPageDone = true;
alert(oPlugin.startAfterPageDone);
oPlugin.startAfterPageDone = false;
alert(oPlugin.startAfterPageDone);
startAfterPageDoneUrl - read/write, return or set the address where the plugin will be auto started
Example:
oPlugin.startAfterPageDoneUrl='*maxthon.com*|*maxthon.cn*';
alert(oPlugin.startAfterPageDoneUrl);
Methods:
config() - open plugin configuration dialog (config.html)
Example:
oPlugin.config();
remove() - delete the plugin
Example:
oPlugin.remove();
[edit] Mscript
Maxthon 2.0 supports custom mscript in addition to normal script for script button plugins. Unlike normal script,mscript is not run on webpages and so mscript does not subject to security restrictions imposed on normal script, and does not need to worry about being exploit by webpages. mscript can greatly enhance the functionality of script plugins since mscript can operate with scripting disabled and mscript can access contents in cross domain frames. To use mscript in a Script button plugin, replace the <script...> tag with <mscript...>
Example - the following script button plugin can disable scripting in the current page by changing Maxthon's content control:
<script language="javascript">
external.m2_run_cmd(%max_security_id, 33175);
</script>
But after scripting is disabled, the plugin cannot operate. So it cannot re-enable scripting in the current page. On the other hand the following mscript plugin can operate with scripting disabled, so it can renable scripting in the current page.
<mscript language="javascript">
external.m2_run_cmd(0, 33175);
</script>
Note an arbitrary number can be used as %max_security_id when mscript is used
How to obtain the Security ID
1. Script button plugins can use "%max_security_id" for the Security ID
2. Script sidebar plugins and HTML button plugins have to load "max.src", a script generated by Maxthon. Then "max_security_id" can be used。
<script src=max.src></script>
Reference for Maxthon Plugin Commands
Unless specified otherwise, the following plugin commands are applicable for both Maxthon 2.0 and Maxthon 1.X。
1. max_version - return Maxthon's version number
Example:
alert(external.max_version);
2. max_language_id - return Maxthon's language ID
Example:
alert(external.max_language_id);
Note: Maxthon 2.0 and Maxthon 1.X have different language ID format
3. tab_count - return the number of tabs opened by Maxthon
Example:
alert(external.tab_count);
4. cur_sel - return the index of Maxthon's current tab
Example:
alert(external.cur_sel);
5. m2_plugin_folder( security_id , plugin_name ) - return the folder path of the specified plugin
Example:
alert(external.m2_plugin_folder( %max_security_id , 'ViewSource!'));
6. m2_run_cmd( security_id , command_id ) - run the specified command ID
Example:
external. m2_run_cmd( %max_security_id , 32772 ));
Note: Maxthon 2.0 and Maxthon 1.X have different command ID. Command ID can be found in Maxthon's language file.
7. get_tab( security_id , tab_index ) - return the window object of the specifed tab
Example:
var oWin=external.get_tab(%max_security_id, 0);
alert(oWin.document.URL);
8. activate_tab( security_id , tab_index ) - activate the specified tab
Example:
external.activate_tab(%max_security_id, 0);
9. close_tab( security_id , tab_index ) - close the specified tab
Example:
external.close_tab(%max_security_id, 0);
10. readFile( security_id, plugin_name, file_name) - read the content of specified text file
Example:
var sText=external.readFile(%max_security_id, 'ViewPage', 'readme.txt');
alert(sText);
11. writeFile( security_id, plugin_name, file_name, content ) - write content to the specific text file
Example:
external.writeFile(%max_security_id, 'ViewPage', 'test.txt', 'This is the file content');
12. m2_readIni( security_id, plugin_name , file_name , section_name , key , default_value) - read data from specific INI file
Example:
var sDownloadTool=external.m2_readIni(%max_security_id, 'ViewPage', 'plugin.ini', 'Settings', 'Tool', );
alert(sDownloadTool);
13. m2_writeIni( security_id , plugin_name , file_name , section_name , key , value ) - write data to specific INI file
Example:
external.m2_writeIni(%max_security_id, 'ViewPage', 'test.ini', 'Config', 'height', '100px');
14. max_modelessDialog( security_id , url , option , attr , window ) - returns a modeless web page dialog
Example:
var oDialog= external.max_modelessDialog( %max_security_id , 'blank.html', window , , window );
var oDoc=oDialog.document;
oDoc.write('Testing');
oDoc.close();
15. max_activex(security_id ,program_id) - return specified ActiveX object
Example:
var oWSH=external.max_activex(%max_security_id, 'WScript.Shell');
oWSH.run('notepad.exe');
16. m2_search_text(security_id) - return the text in search bar
Example:
alert(m2_search_text(%max_security_id));
17. max_callback(event_name) - a function which is run when certain Maxthon events happen (for HTML button plugins and Script sidebar plugins)
HTML button plugins and Script sidebar plugins can implement the max_callback function for reacting to certain Maxthon browser events like switching to a different tab.
Example:
function max_callback(x){
if(x=='tab_change') alert('Current tab is changed.');
}
By checking the parameter of the max_callback function, plugin can get the following browser events:
HTML button plugins
tab_change – after the current tab is switched
document_Complete - after the current tab is fully loaded
self_destroy - when the html is unloaded, usually when Maxthon exits
Script sidebar plugins
sidebar_tab_change - after the current tab is switched
sidebar_activate - when the sidebar plugin is activated
sidebar_deactivate - when the sidebar plugin is deactivated
sidebar_unload - when the sidebar plugin is unloaded (Maxthon is closed)
18. max_getObj (for Maxthon 2.0 only) - return various Maxthon objects, including:
Info - general information about Maxthon
Adhunter – about Ad Hunter
FavManager – about Favorites
RssManager – about RSS
PluginManager - about Plugins, for Maxthon 2.0.5 or later
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
Info Object supports the following property and method:
Property:
fileProxy - read-only, returns the path of the current user's proxy configuration document.
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
alert(oInfo.fileProxy);
folderUser - read-only, returns the path of the profile folder of the current user
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
alert(oInfo. folderUser);
Method:
getFolderPluginData(plugin_name) - obtain the path of plugin data storage folder for the current user and the plugin
Example:
var oInfo=external.max_getObj(%max_security_id, 'info');
alert(oInfo.getFolderPluginData('ViewSource!'));
AdHunter object support the following method:
Method:
reloadFilter(filter_name) – reload the specified Maxthon filter (currently content filter only) after modifying the relevant filter
Example:
var oAdHunter=external.max_getObj(%max_security_id, 'AdHunter');
oAdHunter.reloadFilter('content');
enableFilter(filter_name, bEnable) – enable or disable Maxthon's 'content' or 'popup' filter
Example:
var oAdHunter=external.max_getObj(%max_security_id, 'AdHunter');
oAdHunter.enableFilter ('content', false);
PluginManager object support the following method:
getPluginFolder - return Maxthon main plugin folder path
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
alert(oPluginManager.getPluginFolder)
getCount - return the number of all installed plugins, both enabled and disabled
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
alert(oPluginManager.getCount)
getList - return a list which contains information like name, author etc of all plugins
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
alert(oPluginManager.getList)
getPlugin(Index) - Index is a number, return the corresponding plugin object
Example:
var oPluginManager=external.max_getObj(%max_security_id, 'PluginManager');
var oPlugin=oPluginManager.getPlugin(0);
The plugin object returned from getPlugin(Index) supports the following property and method:
Property:
title - read only, return plugin name
Example:
alert(oPlugin.title);
folderName - read only, return plugin's folder name
Example:
alert(oPlugin.folderName);
fullPath - read only, return plugin folder's full path
Example:
alert(oPlugin.fullPath);
enable - read/write, return or set if the plugin is enabled
Example:
oPlugin.enable=false;
alert(oPlugin.enable);
oPlugin.enable=true;
alert(oPlugin.enable);
startAfterPageDone - read/write, return or set if the plugin is auto started
Example:
oPlugin.startAfterPageDone = true;
alert(oPlugin.startAfterPageDone);
oPlugin.startAfterPageDone = false;
alert(oPlugin.startAfterPageDone);
startAfterPageDoneUrl - read/write, return or set the address where the plugin will be auto started
Example:
oPlugin.startAfterPageDoneUrl='*maxthon.com*|*maxthon.cn*';
alert(oPlugin.startAfterPageDoneUrl);
Methods:
config() - open plugin configuration dialog (config.html)
Example:
oPlugin.config();
remove() - delete the plugin
Example:
oPlugin.remove();
[edit] Mscript
Maxthon 2.0 supports custom mscript in addition to normal script for script button plugins. Unlike normal script,mscript is not run on webpages and so mscript does not subject to security restrictions imposed on normal script, and does not need to worry about being exploit by webpages. mscript can greatly enhance the functionality of script plugins since mscript can operate with scripting disabled and mscript can access contents in cross domain frames. To use mscript in a Script button plugin, replace the <script...> tag with <mscript...>
Example - the following script button plugin can disable scripting in the current page by changing Maxthon's content control:
<script language="javascript">
external.m2_run_cmd(%max_security_id, 33175);
</script>
But after scripting is disabled, the plugin cannot operate. So it cannot re-enable scripting in the current page. On the other hand the following mscript plugin can operate with scripting disabled, so it can renable scripting in the current page.
<mscript language="javascript">
external.m2_run_cmd(0, 33175);
</script>
Note an arbitrary number can be used as %max_security_id when mscript is used