WebPageQueryLink Function

Action

This function queries the currently active page context for hyperlinks. The query can be specified by defining a substring which has to occur in the hyperlinks URL (tag “href”) or by providing the number of the link. The results are the hyperlink’s name, the URL and the sequential number if the hyperlink is found.

Include file

WebAPI.bdh

Syntax

WebPageQueryLink( in  sUrlFilter   : string allownull,
                  in  nLinkNo      : number optional,
                  out sLinkName    : string optional,
                  in  nLinkNameLen : number optional,
                  out sUrl         : string optional,
                  in  nMaxUrlLen   : number optional,
                  in  sFrame       : string optional,
                  in  nMode        : number optional ): number;

Return value

  • the sequential number of the hyperlink found.

  • zero otherwise.

Parameter Description
sUrlFilter String which has to occur in the hyperlink's URL (tag “href”). Specify NULL to query for all hyperlinks.
nLinkNo Hyperlink number to query for. If sUrlFilter is NULL, the function queries the n-th hyperlink in the page. Otherwise, the function queries the n-th hyperlink that matches the filter. Specify zero to use only the filter.
sLinkName String variable that receives the name of the hyperlink (optional). See the WebPageLink function for naming rules.
nLinkNameLen Maximum length of the hyperlink name to return (optional). This value must be less than or equal to the size of the string variable sLinkName.
sUrl String receiving the URL the hyperlink refers to (optional). See the WebPageLink function for naming rules.
nMaxUrlLen Maximum length of the URL string to return. This value must be less than or equal to the size of the string variable sUrl.
sFrame The name of the frame the document is assigned to (optional). If this parameter is provided, the hyperlink is searched only within this frame document.
nMode

This can be any combination of the following values (optional):

  • WEB_QUERY_FLAG_LAST_PAGE (default)

  • WEB_QUERY_FLAG_HISTORY

  • WEB_QUERY_FLAG_STORED_CONTEXTS

Example

dcltrans
  transaction TMain
  var
    nLinkNo : number;
    sLink   : string(100);
    sUrl    : string(200);
  begin
    WebPageUrl("http://www.mytestmall.com/welcome_new.asp",
               "New Shopper");
    WebPageLink("Store Directory", "Product Listing Page");

    // search for the first hyperlink
    // with the string "pfid" in the URL
    nLinkNo := WebPageQueryLink("pfid", 0, sLink, STRING_COMPLETE, sUrl);

    // write test output
    write("link = "); writeln(sLink);
    write("URL = "); writeln(sUrl);

    // now request the page of the selected product
    WebPageLink(sLink, "SelectProductFromListing");
  end TMain;

Example

dcltrans
  transaction TQueryAllLinks
  var
    sName : string;
    i     : number;
  begin
    WebPageUrl("http://www.mycompany.com/");

    i := 1;
    while (WebPageQueryLink(NULL, i, sName, STRING_COMPLETE) > 0) do
      Print(string(i) + ". link: " + sName);
      i := i+1;
    end;

    Print(string(i-1) + " hyperlinks found");
  end TQueryAllLinks;