Les scripts de Maxthon v2.0

De Wiki Francophone de Maxthon

Version: 2.0.1 Last Modified: 2006-07-17 4:24 PM


Overview

Maxthon Browser has extended the DHTML support of IE by adding several new extensions which can be called by scripting language such as Javascript and VBScript.

These APIs can be called via the window.external object in a HTML page or a script plugin made for Maxthon Browser.

Some functions will require a security_id as first parameter. These Functions can only be used by Plugins.
In order to get a security_id for your plugin, you can do the following:

Button Plugins

Put a %max_security_id in your script, such as:

var security_id=%max_security_id;

Then you can use the variable security_id in your script.

Sidebar Plugins

A file named max.src will be created in your plugin's folder, include this file in your HTML file:

<script type="text/javascript" src="max.src"></script>

Then use variable max_security_id for security id parameter in your script.


Index

Extended Properties

General Methods

Tab Related Methods

File Related Methods


Extended Properties

max_version

Remarks:

This property will return a string of Maxthon Browser Version Number.
The return string is formatted like "2.1.0.600".

It's sugguested use this property to determine whether Maxthon Browser is running.

Requirements:

Maxthon Version 2.0+

Example:

alert('Maxthon Version: '+external.max_version);


max_language_id

Remarks:

This property will return current language id of Maxthon Browser.

The Language ID has change to use Language Identifiers defined in Microsoft Windows since Maxthon Browser 2.0.
A list of Maxthon's Language IDs can be found at:
http://msdn.microsoft.com/library/?url=/library/en-us/intl/nls_238z.asp

Requirements:

Maxthon Version 1.0+

Example:

alert('Language ID='+external.max_language_id);


====current_tab==== (formerly cur_sel ) Not Implemented

Remarks:
This property will return an integer number as the index of the tab which is activated.
null will be returned if there is no tab opened.
current_tab is introduced in Maxthon 2.0 as a replacement of cur_sel because the old property name is too obscure to understand.

Requirements:
Maxthon Version 2.0+ (use cur_sel for 1.x versions)

Example:
alert('Current Tab Index: '+external.current_tab);


tab_count

Remarks:
This property will return current tab count as an integer.

Requirements:
Maxthon Version 1.0+

Example:

alert('Tabs Count: '+external.tab_count);


General Methods

addFavorite(url [, title])

Parameters:

url : string
The url to add.

title : string
Optional. The title of the url.

Remarks:
Show the Add Favorite dialog to ask user to add a new Favorites Item.
This function will return false if user cancelled this operation.

Requirements:
Maxthon Version 1.0+

Example:

external.addFavorite("http://www.maxthon.com");

external.addFavorite("http://www.maxthon.com", "Maxthon Official Site");


addProxy(name, address, type)

Parameters:

name : string
The display name of proxy.

address : string
The IP address or Domain name of proxy.

type : integer
A number indicates the speed rating of proxy.
= HTTP Proxy, 1 = SOCKS4A Proxy, 2 = SOCKS5 Proxy

Remarks:
Add a new proxy into Maxthon's proxy list. A dialog will be shown to the user.
This function will return false if user cancelled this operation.

Requirements:
Maxthon Version 2.0+

Example:

external.addProxy("My proxy","192.168.1.0:8080", 1);


addFilter(url_mask, type)

Parameters:

url_mask : string
Address mask to match blocked addresses. Supports Regular Expression.

type : integer
A number indicates which Filter list to add.
= Popup Filter, 1 = Content Filter

Remarks:
Add a new filter policy into Maxthon. A dialog will be shown to the user.
This function will return false if user cancelled this operation.

Requirements:
Maxthon Version 2.0+

Example:

external.addFilter("http://www.advertisement.com/img/*", );


max_addProxyProvider(URL)

Parameters:

URL : string
The URL of proxy list file. File format please refer to [proxyprovider.htm this document].

Remarks:
Add a new Proxy Provider into Maxthon Broser. A dialog will be shown to the user.
This function will return false if user cancelled this operation.

Requirements:
Maxthon Version 2.0+

Example:

external.max_addProxyProvider("http://www.freeproxy.cn/m2proxy/proxylist.xml");


m2_run_cmd(security_id, command_id)

Parameters:

security_id : string
Maxthon's Security ID.

command_id : integer
The internal command ID of Maxthon.

Remarks:
This function will call a Maxthon's command with specified command_id.
Most usable Command IDs can be found in the language file inside Maxthon's language folder.
Command ID might be different between versions. Please do not use this function if not required.

Requirements:
Maxthon Version 1.0+

Example:

external.m2_run_cmd(security_id, 32772); // Open a Blank Page


m2_search_text(security_id)

Parameters:

security_id : string
Maxthon's Security ID.

Remarks:
This function will return the text in Maxthon's Search Box as a string.

Requirements:
Maxthon Version 1.2+

Example:

var searchText=external.m2_search_text(security_id);


m2_plugin_folder(security_id, plugin_name)

Parameters:

security_id : string
Maxthon's Security ID.

plugin_name : string
The name of the plugin as defined in plugin.ini.

Remarks:
This function will return the local folder path of specified plugin as a string.

Requirements:
Maxthon Version 1.2+

Example:

var pluginPath=external.m2_plugin_folder(security_id, "ViewSource!");


m2_callerName(security_id, plugin_name)

Parameters:

security_id : string
Maxthon's Security ID.

plugin_name : string
The name of the plugin as defined in plugin.ini.

Remarks:
This function will tell Maxthon the next function call is from a plugin.
This function is usually used before the window.open() method to bypass the Popup Blocker of Maxthon for the plugin.

Requirements:
Maxthon Version 1.2+

Example:

external.m2_callerName(security_id, "ViewSource!");
window.open("about:blank");


max_actSideBarItem(plugin_name)

Parameters:

plugin_name : string
The name of the plugin as defined in plugin.ini.

Remarks:
This function will activate the sidebar plugins with the given name. 

Requirements:
Maxthon Version 1.2+

Example:

external.max_actSideBarItem("Calculator++");


max_modelessDialog(security_id, url, arguments, features, parent_window)

Parameters:

security_id : string
Maxthon's Security ID.

url : string
The url of modeless dialog content.

arguments : variant
The arguments pass to the modeless dialog's window.dialogArguments object.

features : string
A String that specifies the window ornaments for the dialog box.

parent_window : object
The parent window object of the dialog.

Remarks:
This function is almost the same as window.showModelessDialog() but with two more parameters.
With the security_id your plugin can bypass Maxthon's Popup Blocker.
With the parent_window you can make the dialog being a child of another tab's window.

Requirements:
Maxthon Version 1.2+

Example:

external.max_modelessDialog(security_id, "about:blank", {"userid": 7, "key": "d3fe3asd"}, "status:no; help:no; resizable:yes; scroll:yes;", window);


get_tab(security_id, index)

Parameters:

security_id : string
Maxthon's Security ID.

index : integer
The index of the tab to get.

Remarks:
This function will get the window object of specified tab in Maxthon.
null will be returned if the tab does not exist.

Requirements:
Maxthon Version 1.0+

Example:

var objTab=external.get_tab(security_id, 5);


activate_tab(security_id, index)

Parameters:

security_id : string
Maxthon's Security ID.

index : integer
The index of the tab to be activated.

Remarks:
This function will activate the specified tab in Maxthon.
Nothing will happen if the tab does not exist.

Requirements:
Maxthon Version 1.0+

Example:

external.activate_tab(security_id, 1);


close_tab(security_id, index)

Parameters:

security_id : string
Maxthon's Security ID.

index : integer
Integer. The index of the tab to close.

Remarks:
This function will close the tab which index represents.
Nothing will happen if the tab does not exist.

Requirements:
Maxthon Version 1.0+

Example:

external.close_tab(security_id, );


readFile(security_id, plugin_name, file_name)

Parameters:

security_id : string
Maxthon's Security ID.

plugin_name : string
The name of calling plugin as defined in plugin.ini

file_name : string
The file to read.

Remarks:
This function can only be used in a plugin.
The function will return the file content in string when success.
If the plugin is not enabled or the plugin_name is not found, the function will fail and return null.

Requirements:
Maxthon Version 1.0+

Example:

var strFile=external.readFile(security_id, "Test plugin", "plugin.ini");


writeFile(security_id, plugin_name, file_name, content)

Parameters:

security_id : string
Maxthon's Security ID.

plugin_name : string
The name of calling plugin as defined in plugin.ini

file_name : string
The file to write.

content : string
File content string to write.

Remarks:
This function can only be used in a plugin.
This function will return true when success.
If the file is not found, the plugin is not enabled or the plugin_name is not found, the function will fail and return false.
If a file with the same name exists, it will be overwritten.

Requirements:
Maxthon Version 1.0+

Example:

external.writeFile(security_id, "Test plugin", "setting.ini", "username=abc\npass=qwrxcv");


m2_readIni(security_id, plugin_name, file_name, section_name, key, default_value)

Parameters:

security_id : string
Maxthon's Security ID.

plugin_name : string
The name of calling plugin as defined in plugin.ini.

file_name : string
The name of the INI file to read.

section_name : string
The INI section to read, without brackets [ ].

key : string
The key of the entry to read.

default_value : string
The default value to return if the key does not exist.

Remarks:
This function will read the value of key under section section_name in INI file file_name.
The INI file must be placed inside the folder of plugin plugin_name.
The value will be returned as a string if success.
If the file does not exist, the section does not exist or the key does not exist, the default_value will be returned.

Requirements:
Maxthon Version 1.0+

Example:

var saveCount = external.m2_readIni(security_id, "TestPlugin", "settings.ini", "general", "saveCount", "0");


m2_writeIni(security_id, plugin_name, file_name, section_name, key, value)

Parameters:

security_id : string
Maxthon's Security ID.

plugin_name : string
The name of calling plugin as defined in plugin.ini.

file_name : string
The name of the INI file to write.

section_name : string
The INI section to write, without brackets [ ].

key : string
The key of the entry to write.

value : string/integer
The value to write.

Remarks:
This function will write a key and value pair entry under section section_name in INI file file_name.
The INI file can only be writen inside the folder of plugin plugin_name.
If the file does not exist, the section does not exist or the key does not exist, they will be created automatically.
This function will return true when success and false when failed.

Requirements:
Maxthon Version 1.0+

Example:

external.m2_writeIni(security_id, "TestPlugin", "settings.ini", "general", "saveCount", 25);


Base de connaissances de Maxthon 2.0