Différences entre les versions de « Les scripts de Maxthon v2.0 »

De Wiki Francophone de Maxthon
Aller à la navigation Aller à la recherche
Ligne 48 : Ligne 48 :
==Index==
==Index==


====Extended Properties====
====''Extended Properties''====
* [[#max_version|max_version]] : Get current version of Maxthon Browser
* ''[[#max_version|max_version]] : Get current version of Maxthon Browser''
* [[#max_language_id|max_language_id]] : Get current language id of Maxthon UI
* ''[[#max_language_id|max_language_id]] : Get current language id of Maxthon UI''
* [[#current_tab|current_tab (cur_sel)]] : Get current tab's index
* ''[[#current_tab|current_tab (cur_sel)]] : Get current tab's index''
* [[#tab_count|tab_count]] : Get current opened tabs' count
* ''[[#tab_count|tab_count]] : Get current opened tabs' count''


====General Methods====
====Propriétés étendues====
* [[#addFavorite|addFavorite()]] : Call the Add Favorites dialog
* [[#max_version|max_version]] : Obtenir la version courante de Maxthon
* [[#addProxy|addProxy()]] : Call the Add Proxy dialog
* [[#max_language_id|max_language_id]] : Obtenir l'id de la langue courante de l'interface utilisateur de Maxthon
* [[#addFilter|addFilter()]] : Call the Add Filter dialog
* [[#current_tab|current_tab (cur_sel)]] : Obtenir l'index de l'onglet en cours
* [[#max_addProxyProvider|max_addProxyProvider()]] : Call the Add Proxy Provider dialog
* [[#tab_count|tab_count]] : Obtenir le nombre d'onglets ouvert en cours
* [[#m2_run_cmd|m2_run_cmd()]] : Execute Maxthon functions by Command ID
* [[#m2_search_text|m2_search_text()]] : Get search string in Maxthon's Search Box
* [[#m2_plugin_folder|m2_plugin_folder()]] : Get local folder path of a plugin


====Tab Related Methods====
====''General Methods''====
* [[#get_tab|get_tab()]] : Get a tab's window object by index
* ''[[#addFavorite|addFavorite()]] : Call the Add Favorites dialog''
* [[#activate_tab|activate_tab()]] : Activate a tab by index
* ''[[#addProxy|addProxy()]] : Call the Add Proxy dialog''
* [[#close_tab|close_tab()]] : Close a tab by index
* ''[[#addFilter|addFilter()]] : Call the Add Filter dialog''
* ''[[#max_addProxyProvider|max_addProxyProvider()]] : Call the Add Proxy Provider dialog''
* ''[[#m2_run_cmd|m2_run_cmd()]] : Execute Maxthon functions by Command ID''
* ''[[#m2_search_text|m2_search_text()]] : Get search string in Maxthon's Search Box''
* ''[[#m2_plugin_folder|m2_plugin_folder()]] : Get local folder path of a plugin''


====File Related Methods====
====Méthodes générales====
* [[#readFile|readFile()]] : Read a file's content
* [[#addFavorite|addFavorite()]] : Appeler la boîte de dialogue Ajouter des Favoris
* [[#writeFile|writeFile()]] : Write data to a file
* [[#addProxy|addProxy()]] : Appeler la boîte de dialogue Ajouter un Proxy
* [[#m2_readIni|m2_readIni()]] : Read an INI file
* [[#addFilter|addFilter()]] : Appeler la boîte de dialogue Ajouter un filtre
* [[#m2_writeIni|m2_writeIni()]] : Write to an INI file
* [[#max_addProxyProvider|max_addProxyProvider()]] : Appeler la boîte de dialogue Ajouter un fournisseur de Proxy
* [[#m2_run_cmd|m2_run_cmd()]] : Exécuter la fonction de Maxthon correspondant à la commande ID
* [[#m2_search_text|m2_search_text()]] : Obtenir la chaîne de recherche de la barre de recherche de Maxthon
* [[#m2_plugin_folder|m2_plugin_folder()]] : Obtenir le dossier local des Plugins


====''Tab Related Methods''====
* ''[[#get_tab|get_tab()]] : Get a tab's window object by index''
* ''[[#activate_tab|activate_tab()]] : Activate a tab by index''
* ''[[#close_tab|close_tab()]] : Close a tab by index''


==Extended Properties==
====Méthodes associées aux onglets====
* [[#get_tab|get_tab()]] : Obtenir l'objet d'un onglet par index
* [[#activate_tab|activate_tab()]] : Activer un onglet par index
* [[#close_tab|close_tab()]] : Fermer un onglet par index
 
====''File Related Methods''====
* ''[[#readFile|readFile()]] : Read a file's content''
* ''[[#writeFile|writeFile()]] : Write data to a file''
* ''[[#m2_readIni|m2_readIni()]] : Read an INI file''
* ''[[#m2_writeIni|m2_writeIni()]] : Write to an INI file''
 
====Méthodes associées aux fichiers====
* [[#readFile|readFile()]] : Lire le contenu d'un fichier
* [[#writeFile|writeFile()]] : Ecrire des données dans un fichier
* [[#m2_readIni|m2_readIni()]] : Lire un fichier INI
* [[#m2_writeIni|m2_writeIni()]] : Ecrire dans un fichier INI
 
 
==Propriétées étendues==


===max_version===
===max_version===

Version du 6 septembre 2006 à 12:06

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:

Vue d'ensemble

Le navigateur Maxthon a amélioré le support du DHTML de IE en ajoutant plusieurs nouvelles extensions qui peuvent être appelées par un langage de script comme Javascript et VBScript.

Ces APIs peuvent être appelées via l'objet window.external dans une page HTML ou par un Plugin de type script réalisé pour Maxthon.

Quelques fonctions nécessiterons security_id comme premier paramètre. Ces fonctions ne peuvent être seulement utilisées par des Plugins.
Afin d'avoir un security_id pour votre plugin, vous devez procéder ainsi :

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.

Plugins de type Bouton

Insérez un %max_security_id dans votre script, comme ceci :

var security_id=%max_security_id;

Ainsi vous pourrez utiliser la variable security_id dans votre 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.

Plugins de type Barre latérale

Un fichier nommé max.src sera créé dans le dossier de votre Plugin, inclure ce fichier dans votre fichier HTML :

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

Ainsi vous pourrez utiliser la variable max_security_id comme paramètre identificateur de sécurité dans votre script.


Index

Extended Properties

Propriétés étendues

General Methods

Méthodes générales

Tab Related Methods

Méthodes associées aux onglets

File Related Methods

Méthodes associées aux fichiers


Propriétées étendues

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