WMLScript How to

来源:互联网 发布:nginx 负载 编辑:程序博客网 时间:2024/06/02 16:22

How to call  a WMLScript from a WML page
如何从一个WML页面中请求一个WMLScript程序?

Notice that WMLScripts are not embedded in WML pages. The WML pages only contains references to script URLs.
注意:WML 页面并不包含WML脚本语言,它只拥有URLs的脚本参数。

In the example below; if you select the go label the external script will direct you to http://www.w3schools.com/wap.wml:
在下面的例子中,如果你选择使用了“go”标签,扩展标签将指向http://www.w3pop.com/wap.wml:

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml">
<wml><card id="no1" title="Go to URL"><do type="options" label="Go"><go href="check.wmls#go_url('W3Schools')"/></do></card></wml>

The red line above contains a reference to a WMLScript. The script is in a file called check.wmls, and the name of the function is go_url.
上述代码的红字部分包含了一个WMLScript参数。这个脚本位于一个名为“check.wmls”文件内,且函数的名称为“go_url”。

Here is the WML page called check.wmls:
下面展示的是名为“check.wmls”的WML页面:

extern function go_url(the_url){if (the_url=="W3Schools"){WMLBrowser.go("http://www.w3schools.com/wap.wml")}}

Note that the function is using the extern keyword. When using this keyword the function can be called by other functions or WML events outside the .wmls file. To keep a function private, drop the extern keyword.
注意:这里的函数使用的是“extern”关键词。当使用这个关键词时,这个函数便可以被其他的函数或者“.wmls”文件之外的的WML事件请求。如果你想让这个函数只能在当前文档中使用,你必须放弃使用“extern”关键词。