« Les scripts de Maxthon v2.0 » : différence entre les versions

De Wiki Francophone de Maxthon
Ldfa (discussion | contributions)
Aucun résumé des modifications
Ldfa (discussion | contributions)
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
Version: 2.0.1<br /> Last Modified: 2006-07-17 4:24 PM
Version: 2.0.1
Last Modified: 2006-07-17 4:24 PM




Ligne 5 : Ligne 6 :
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.
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 <span class="keyword">window</span>.<span class="keyword">external</span> object in a HTML page or a script plugin made for Maxthon Browser.
These APIs can be called via the <span style="color: #000066;font-weight: bold;">window</span>.<span style="color: #000066;font-weight: bold;">external</span> object in a HTML page or a script plugin made for Maxthon Browser.


Some functions will require a <span class="flag">security_id</span> as first parameter. These Functions can only be used by Plugins.<br /> In order to get a <span class="flag">security_id</span> for your plugin, you can do the following:
Some functions will require a <span style="color: #990000;">security_id</span> as first parameter. These Functions can only be used by Plugins.<br /> In order to get a <span style="color: #990000;">security_id</span> for your plugin, you can do the following:


====Button Plugins====
====Button Plugins====
Put a <span class="flag">%max_security_id</span> in your script, such as:
Put a <span style="color: #990000;">%max_security_id</span> in your script, such as:


<span class="keyword">var</span> security_id=<span class="flag">%max_security_id</span><nowiki>;</nowiki>
<span style="color: #000066;font-weight: bold;">var</span> security_id=<span style="color: #990000;">%max_security_id</span><nowiki>;</nowiki>


Then you can use the variable <span class="flag">security_id</span> in your script.
Then you can use the variable <span style="color: #990000;">security_id</span> in your script.


====Sidebar Plugins====
====Sidebar Plugins====
A file named <span class="flag">max.src</span> will be created in your plugin's folder, include this file in your HTML file:
A file named <span style="color: #990000;">max.src</span> will be created in your plugin's folder, include this file in your HTML file:


<<span class="keyword">script</span> <span class="flag">type</span><nowiki>=</nowiki><span class="string">"text/javascript"</span> <span class="flag">src</span><nowiki>=</nowiki><span class="string">"max.src"</span>></<span class="keyword">script</span>>
<<span style="color: #000066;font-weight: bold;">script</span> <span style="color: #990000;">type</span><nowiki>=</nowiki><span style="color: #0000FF;">"text/javascript"</span> <span style="color: #990000;">src</span><nowiki>=</nowiki><span style="color: #0000FF;">"max.src"</span>></<span style="color: #000066;font-weight: bold;">script</span>>


Then use variable <span class="flag">max_security_id</span> for security id parameter in your script.
Then use variable <span style="color: #990000;">max_security_id</span> for security id parameter in your script.




Ligne 56 : Ligne 57 :


===max_version===
===max_version===
<div class="indent">
<div style="margin-left: 10px;">


====Remarks:====
====Remarks:====
This property will return a string of Maxthon Browser Version Number.<br /> The return string is formatted like <span class="string">"2.1.0.600"</span>.
This property will return a string of Maxthon Browser Version Number.<br /> The return string is formatted like <span style="color: #0000FF;">"2.1.0.600"</span>.


It's sugguested use this property to determine whether Maxthon Browser is running.
It's sugguested use this property to determine whether Maxthon Browser is running.
Ligne 69 : Ligne 70 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<div class="codeblock"><span class="keyword">alert</span>(<span class="string">'Maxthon Version: '</span>+<span class="keyword">external</span>.<span class="keyword">max_version</span>);</div></div>
<div style="margin: 5px;padding: 10px;background: #F3F3F3;border: 1px dashed #CCCCCC;"><span style="color: #000066;font-weight: bold;">alert</span>(<span style="color: #0000FF;">'Maxthon Version: '</span>+<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">max_version</span>);</div></div>


===max_language_id===
===max_language_id===
<div class="indent">
<div style="margin-left: 10px;">


====Remarks:====
====Remarks:====
Ligne 85 : Ligne 86 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">alert</span>(<span class="string">'Language ID='</span>+<span class="keyword">external</span>.<span class="keyword">max_language_id</span>);
<span style="color: #000066;font-weight: bold;">alert</span>(<span style="color: #0000FF;">'Language ID='</span>+<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">max_language_id</span>);


</div>
</div>


====current_tab '''(formerly''' cur_sel ''')''' <span class="note">Not Implemented</span>====
====current_tab '''(formerly''' cur_sel ''')''' <span style="color: #FFFFFF;background-color: #CC0000;">Not Implemented</span>====


<div class="indent">
<div style="margin-left: 10px;">


=====Remarks:=====
=====Remarks:=====


  This property will return an integer number as the index of the tab which is activated.<br /><span class="flag">null</span> will be returned if there is no tab opened.<br /><span class="keyword">current_tab</span><span class="warn"> is introduced in Maxthon 2.0 as a replacement of </span><span class="keyword">cur_sel</span><span class="warn"> because the old property name is too obscure to understand.</span><br /><br />
  This property will return an integer number as the index of the tab which is activated.<br /><span style="color: #990000;">null</span> will be returned if there is no tab opened.<br /><span style="color: #000066;font-weight: bold;">current_tab</span><span style="color: #CC0000;font-weight: bold;"> is introduced in Maxthon 2.0 as a replacement of </span><span style="color: #000066;font-weight: bold;">cur_sel</span><span style="color: #CC0000;font-weight: bold;"> because the old property name is too obscure to understand.</span><br /><br />


=====Requirements:=====
=====Requirements:=====


  Maxthon Version 2.0+ (use <span class="keyword">cur_sel</span> for 1.x versions)<br /><br />
  Maxthon Version 2.0+ (use <span style="color: #000066;font-weight: bold;">cur_sel</span> for 1.x versions)<br /><br />


=====Example:=====
=====Example:=====
Ligne 105 : Ligne 106 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<div class="codeblock"><span class="keyword">alert</span>(<span class="string">'Current Tab Index: '</span>+<span class="keyword">external</span>.<span class="keyword">current_tab</span>);</div></div>
<div style="margin: 5px;padding: 10px;background: #F3F3F3;border: 1px dashed #CCCCCC;"><span style="color: #000066;font-weight: bold;">alert</span>(<span style="color: #0000FF;">'Current Tab Index: '</span>+<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">current_tab</span>);</div></div>


====tab_count====
====tab_count====


<div class="indent">
<div style="margin-left: 10px;">


=====Remarks:=====
=====Remarks:=====
Ligne 123 : Ligne 124 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">alert</span>(<span class="string">'Tabs Count: '</span>+<span class="keyword">external</span>.<span class="keyword">tab_count</span>);
<span style="color: #000066;font-weight: bold;">alert</span>(<span style="color: #0000FF;">'Tabs Count: '</span>+<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">tab_count</span>);


</div>
</div>
Ligne 133 : Ligne 134 :
====addFavorite(''url'' '''[''', ''title''''']''')====
====addFavorite(''url'' '''[''', ''title''''']''')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 141 : Ligne 142 :
=====Remarks:=====
=====Remarks:=====


  Show the Add Favorite dialog to ask user to add a new Favorites Item.<br /> This function will return <span class="bool">false</span> if user cancelled this operation.<br /><br />
  Show the Add Favorite dialog to ask user to add a new Favorites Item.<br /> This function will return <span style="color: #CC0000;font-weight: bold;">false</span> if user cancelled this operation.<br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 151 : Ligne 152 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">external</span>.<span class="keyword">addFavorite</span>(<span class="string">"http://www.maxthon.com"</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">addFavorite</span>(<span style="color: #0000FF;">"http://www.maxthon.com"</span>);


[javascript:v() [Demo 2]]
[javascript:v() [Demo 2]]


<span class="keyword">external</span>.<span class="keyword">addFavorite</span>(<span class="string">"http://www.maxthon.com"</span>, <span class="string">"Maxthon Official Site"</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">addFavorite</span>(<span style="color: #0000FF;">"http://www.maxthon.com"</span>, <span style="color: #0000FF;">"Maxthon Official Site"</span>);


</div>
</div>
Ligne 161 : Ligne 162 :
====addProxy(''name'', ''address'', ''type'')====
====addProxy(''name'', ''address'', ''type'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====


''name'' : string<br /> The display name of proxy.<br /><br />''address'' : string<br /> The IP address or Domain name of proxy.<br /><br />''type'' : integer<br /> A number indicates the speed rating of proxy.<br /> = HTTP Proxy, <span class="number">1</span> = SOCKS4A Proxy, <span class="number">2</span> = SOCKS5 Proxy<br /><br />
''name'' : string<br /> The display name of proxy.<br /><br />''address'' : string<br /> The IP address or Domain name of proxy.<br /><br />''type'' : integer<br /> A number indicates the speed rating of proxy.<br /> = HTTP Proxy, <span style="color: #FF6600;">1</span> = SOCKS4A Proxy, <span style="color: #FF6600;">2</span> = SOCKS5 Proxy<br /><br />


=====Remarks:=====
=====Remarks:=====


  Add a new proxy into Maxthon's proxy list. A dialog will be shown to the user.<br /> This function will return <span class="bool">false</span> if user cancelled this operation.<br /><br />
  Add a new proxy into Maxthon's proxy list. A dialog will be shown to the user.<br /> This function will return <span style="color: #CC0000;font-weight: bold;">false</span> if user cancelled this operation.<br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 179 : Ligne 180 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">external</span>.<span class="keyword">addProxy</span>(<span class="string">"My proxy"</span>,<span class="string">"192.168.1.0:8080"</span>, <span class="number">1</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">addProxy</span>(<span style="color: #0000FF;">"My proxy"</span>,<span style="color: #0000FF;">"192.168.1.0:8080"</span>, <span style="color: #FF6600;">1</span>);


</div>
</div>
Ligne 185 : Ligne 186 :
====addFilter(''url_mask'', ''type'')====
====addFilter(''url_mask'', ''type'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====


''url_mask'' : string<br /> Address mask to match blocked addresses. Supports Regular Expression.<br /><br />''type'' : integer<br /> A number indicates which Filter list to add.<br /> = Popup Filter, <span class="number">1</span> = Content Filter<br /><br />
''url_mask'' : string<br /> Address mask to match blocked addresses. Supports Regular Expression.<br /><br />''type'' : integer<br /> A number indicates which Filter list to add.<br /> = Popup Filter, <span style="color: #FF6600;">1</span> = Content Filter<br /><br />


=====Remarks:=====
=====Remarks:=====
Ligne 203 : Ligne 204 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">external</span>.<span class="keyword">addFilter</span>(<span class="string">"http://www.advertisement.com/img/*"</span>, );
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">addFilter</span>(<span style="color: #0000FF;">"http://www.advertisement.com/img/*"</span>, );


</div>
</div>
Ligne 209 : Ligne 210 :
====max_addProxyProvider(''URL'')====
====max_addProxyProvider(''URL'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 217 : Ligne 218 :
=====Remarks:=====
=====Remarks:=====


  Add a new Proxy Provider into Maxthon Broser. A dialog will be shown to the user.<br /> This function will return <span class="bool">false</span> if user cancelled this operation.<br /><br />
  Add a new Proxy Provider into Maxthon Broser. A dialog will be shown to the user.<br /> This function will return <span style="color: #CC0000;font-weight: bold;">false</span> if user cancelled this operation.<br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 227 : Ligne 228 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">external</span>.<span class="keyword">max_addProxyProvider</span>(<span class="string">"http://www.freeproxy.cn/m2proxy/proxylist.xml"</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">max_addProxyProvider</span>(<span style="color: #0000FF;">"http://www.freeproxy.cn/m2proxy/proxylist.xml"</span>);


</div>
</div>
Ligne 233 : Ligne 234 :
====m2_run_cmd(''security_id'', ''command_id'')====
====m2_run_cmd(''security_id'', ''command_id'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 241 : Ligne 242 :
=====Remarks:=====
=====Remarks:=====


  This function will call a Maxthon's command with specified ''command_id''.<br /> Most usable Command IDs can be found in the language file inside Maxthon's language folder.<br /><span class="warn">Command ID might be different between versions. Please do not use this function if not required.</span><br /><br />
  This function will call a Maxthon's command with specified ''command_id''.<br /> Most usable Command IDs can be found in the language file inside Maxthon's language folder.<br /><span style="color: #CC0000;font-weight: bold;">Command ID might be different between versions. Please do not use this function if not required.</span><br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 249 : Ligne 250 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">m2_run_cmd</span>(<span class="string">security_id</span>, <span class="number">32772</span>); // Open a Blank Page
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">m2_run_cmd</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #FF6600;">32772</span>); // Open a Blank Page


</div>
</div>
Ligne 255 : Ligne 256 :
====m2_search_text(''security_id'')====
====m2_search_text(''security_id'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 271 : Ligne 272 :
=====Example:=====
=====Example:=====


<span class="keyword">var</span> searchText=<span class="keyword">external</span>.<span class="keyword">m2_search_text</span>(<span class="string">security_id</span>);
<span style="color: #000066;font-weight: bold;">var</span> searchText=<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">m2_search_text</span>(<span style="color: #0000FF;">security_id</span>);


</div>
</div>
Ligne 277 : Ligne 278 :
====m2_plugin_folder(''security_id'', ''plugin_name'')====
====m2_plugin_folder(''security_id'', ''plugin_name'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 293 : Ligne 294 :
=====Example:=====
=====Example:=====


<span class="keyword">var</span> pluginPath=<span class="keyword">external</span>.<span class="keyword">m2_plugin_folder</span>(<span class="string">security_id</span>, <span class="string">"ViewSource!"</span>);
<span style="color: #000066;font-weight: bold;">var</span> pluginPath=<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">m2_plugin_folder</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"ViewSource!"</span>);


</div>
</div>
Ligne 299 : Ligne 300 :
====m2_callerName(''security_id'', ''plugin_name'')====
====m2_callerName(''security_id'', ''plugin_name'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 307 : Ligne 308 :
=====Remarks:=====
=====Remarks:=====


  This function will tell Maxthon the next function call is from a plugin.<br /> This function is usually used before the <span class="keyword">window</span>.<span class="keyword">open</span>() method to bypass the Popup Blocker of Maxthon for the plugin.<br /><br />
  This function will tell Maxthon the next function call is from a plugin.<br /> This function is usually used before the <span style="color: #000066;font-weight: bold;">window</span>.<span style="color: #000066;font-weight: bold;">open</span>() method to bypass the Popup Blocker of Maxthon for the plugin.<br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 315 : Ligne 316 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">m2_callerName</span>(<span class="string">security_id</span>, <span class="string">"ViewSource!"</span>);<br /><span class="keyword">window</span>.<span class="keyword">open</span>(<span class="string">"about:blank"</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">m2_callerName</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"ViewSource!"</span>);<br /><span style="color: #000066;font-weight: bold;">window</span>.<span style="color: #000066;font-weight: bold;">open</span>(<span style="color: #0000FF;">"about:blank"</span>);


</div>
</div>
Ligne 321 : Ligne 322 :
====max_actSideBarItem(''plugin_name'')====
====max_actSideBarItem(''plugin_name'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 339 : Ligne 340 :
[javascript:v() [Demo 1]]
[javascript:v() [Demo 1]]


<span class="keyword">external</span>.<span class="keyword">max_actSideBarItem</span>(<span class="string">"Calculator++"</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">max_actSideBarItem</span>(<span style="color: #0000FF;">"Calculator++"</span>);


</div>
</div>
Ligne 347 : Ligne 348 :
====max_modelessDialog(''security_id'', ''url'', ''arguments'', ''features'', ''parent_window'')====
====max_modelessDialog(''security_id'', ''url'', ''arguments'', ''features'', ''parent_window'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 363 : Ligne 364 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">max_modelessDialog</span>(<span class="string">security_id</span>, <span class="string">"about:blank"</span>, {"userid": 7, "key": "d3fe3asd"}, <span class="string">"status:no; help:no; resizable:yes; scroll:yes;"</span>, window);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">max_modelessDialog</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"about:blank"</span>, {"userid": 7, "key": "d3fe3asd"}, <span style="color: #0000FF;">"status:no; help:no; resizable:yes; scroll:yes;"</span>, window);


</div>
</div>
Ligne 371 : Ligne 372 :
====get_tab(''security_id'', ''index'')====
====get_tab(''security_id'', ''index'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 379 : Ligne 380 :
=====Remarks:=====
=====Remarks:=====


  This function will get the '''window''' object of specified tab in Maxthon.<br /><span class="flag">null</span> will be returned if the tab does not exist.<br /><br />
  This function will get the '''window''' object of specified tab in Maxthon.<br /><span style="color: #990000;">null</span> will be returned if the tab does not exist.<br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 387 : Ligne 388 :
=====Example:=====
=====Example:=====


<span class="keyword">var</span> objTab=<span class="keyword">external</span>.<span class="keyword">get_tab</span>(<span class="string">security_id</span>, <span class="number">5</span>);
<span style="color: #000066;font-weight: bold;">var</span> objTab=<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">get_tab</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #FF6600;">5</span>);


</div>
</div>
Ligne 395 : Ligne 396 :
====activate_tab(''security_id'', ''index'')====
====activate_tab(''security_id'', ''index'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 411 : Ligne 412 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">activate_tab</span>(<span class="string">security_id</span>, <span class="number">1</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">activate_tab</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #FF6600;">1</span>);


</div>
</div>
Ligne 419 : Ligne 420 :
====close_tab(''security_id'', ''index'')====
====close_tab(''security_id'', ''index'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 435 : Ligne 436 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">close_tab</span>(<span class="string">security_id</span>, );
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">close_tab</span>(<span style="color: #0000FF;">security_id</span>, );


</div>
</div>
Ligne 443 : Ligne 444 :
====readFile(''security_id'', ''plugin_name'', ''file_name'')====
====readFile(''security_id'', ''plugin_name'', ''file_name'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 459 : Ligne 460 :
=====Example:=====
=====Example:=====


<span class="keyword">var</span> strFile=<span class="keyword">external</span>.<span class="keyword">readFile</span>(<span class="string">security_id</span>, <span class="string">"Test plugin"</span>, <span class="string">"plugin.ini"</span>);<br />
<span style="color: #000066;font-weight: bold;">var</span> strFile=<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">readFile</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"Test plugin"</span>, <span style="color: #0000FF;">"plugin.ini"</span>);<br />


</div>
</div>
Ligne 467 : Ligne 468 :
====writeFile(''security_id'', ''plugin_name'', ''file_name'', ''content'')====
====writeFile(''security_id'', ''plugin_name'', ''file_name'', ''content'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 475 : Ligne 476 :
=====Remarks:=====
=====Remarks:=====


  This function can only be used in a plugin.<br /> This function will return <span class="bool">true</span> when success.<br /> If the file is not found, the plugin is not enabled or the ''plugin_name'' is not found, the function will fail and return <span class="bool">false</span>.<br /><span class="warn">If a file with the same name exists, it will be overwritten.</span><br /><br />
  This function can only be used in a plugin.<br /> This function will return <span style="color: #CC0000;font-weight: bold;">true</span> when success.<br /> If the file is not found, the plugin is not enabled or the ''plugin_name'' is not found, the function will fail and return <span style="color: #CC0000;font-weight: bold;">false</span>.<br /><span style="color: #CC0000;font-weight: bold;">If a file with the same name exists, it will be overwritten.</span><br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 483 : Ligne 484 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">writeFile</span>(<span class="string">security_id</span>, <span class="string">"Test plugin"</span>, <span class="string">"setting.ini"</span>, <span class="string">"username=abc\npass=qwrxcv"</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">writeFile</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"Test plugin"</span>, <span style="color: #0000FF;">"setting.ini"</span>, <span style="color: #0000FF;">"username=abc\npass=qwrxcv"</span>);


</div>
</div>
Ligne 491 : Ligne 492 :
====m2_readIni(''security_id'', ''plugin_name'', ''file_name'', ''section_name'', ''key'', ''default_value'')====
====m2_readIni(''security_id'', ''plugin_name'', ''file_name'', ''section_name'', ''key'', ''default_value'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 507 : Ligne 508 :
=====Example:=====
=====Example:=====


<span class="keyword">var</span> saveCount = <span class="keyword">external</span>.<span class="keyword">m2_readIni</span>(<span class="string">security_id</span>, <span class="string">"TestPlugin"</span>, <span class="string">"settings.ini"</span>, <span class="string">"general"</span>, <span class="string">"saveCount"</span>, <span class="string">"0"</span>);
<span style="color: #000066;font-weight: bold;">var</span> saveCount = <span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">m2_readIni</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"TestPlugin"</span>, <span style="color: #0000FF;">"settings.ini"</span>, <span style="color: #0000FF;">"general"</span>, <span style="color: #0000FF;">"saveCount"</span>, <span style="color: #0000FF;">"0"</span>);


</div>
</div>
Ligne 515 : Ligne 516 :
====m2_writeIni(''security_id'', ''plugin_name'', ''file_name'', ''section_name'', ''key'', ''value'')====
====m2_writeIni(''security_id'', ''plugin_name'', ''file_name'', ''section_name'', ''key'', ''value'')====


<div class="indent">
<div style="margin-left: 10px;">


=====Parameters:=====
=====Parameters:=====
Ligne 523 : Ligne 524 :
=====Remarks:=====
=====Remarks:=====


  This function will write a ''key'' and ''value'' pair entry under section ''section_name'' in INI file ''file_name''.<br /> The INI file can only be writen inside the folder of plugin ''plugin_name''.<br /> If the file does not exist, the section does not exist or the key does not exist, they will be created automatically.<br /> This function will return <span class="bool">true</span> when success and <span class="bool">false</span> when failed.<br /><br />
  This function will write a ''key'' and ''value'' pair entry under section ''section_name'' in INI file ''file_name''.<br /> The INI file can only be writen inside the folder of plugin ''plugin_name''.<br /> If the file does not exist, the section does not exist or the key does not exist, they will be created automatically.<br /> This function will return <span style="color: #CC0000;font-weight: bold;">true</span> when success and <span style="color: #CC0000;font-weight: bold;">false</span> when failed.<br /><br />


=====Requirements:=====
=====Requirements:=====
Ligne 531 : Ligne 532 :
=====Example:=====
=====Example:=====


<span class="keyword">external</span>.<span class="keyword">m2_writeIni</span>(<span class="string">security_id</span>, <span class="string">"TestPlugin"</span>, <span class="string">"settings.ini"</span>, <span class="string">"general</span>", <span class="string">"saveCount"</span>, <span class="number">25</span>);
<span style="color: #000066;font-weight: bold;">external</span>.<span style="color: #000066;font-weight: bold;">m2_writeIni</span>(<span style="color: #0000FF;">security_id</span>, <span style="color: #0000FF;">"TestPlugin"</span>, <span style="color: #0000FF;">"settings.ini"</span>, <span style="color: #0000FF;">"general</span>", <span style="color: #0000FF;">"saveCount"</span>, <span style="color: #FF6600;">25</span>);


</div>
</div>
<br /><br />

Version du 16 août 2006 à 15:38

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

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

General Methods

  • [#addFavorite addFavorite()] : Call the Add Favorites dialog
  • [#addProxy addProxy()] : Call the Add Proxy dialog
  • [#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

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

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


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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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

[javascript:v() [Demo 2]]

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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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:

[javascript:v() [Demo 1]]

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);