Developers › Dev.Opera

opera.extension.urlfilter.block.add()

December 6, 2011 · by Opera Software

Description:

Adds a rule to the virtual list of blocked URLs.

Parameters:

  • rule: The rule (e.g. domain) to block.

Syntax:

void add (<DOMString> rule)

Example:

<!-- 
  The configuration file ('config.xml').
-->
<?xml version='1.0' encoding='utf-8'?>
<widget xmlns="http://www.w3.org/ns/widgets">
    <feature name="opera:urlfilter"/>
</widget>
//
// The background process (e.g. index.html) 
//

// Store and retrieve a list of URLs in the extension's preferences
widget.preferences['blacklist'] = ['http://opera.com/*', 'http://*.opera.com/*'];
var blacklist = widget.preferences['blacklist'].split(',');

// Assign the URLFilter object to a variable for efficiency
var filter = opera.extension.urlfilter;

// Loop through the array of sites and add each one to the "block" list
for (var i = 0, len = blacklist.length; i < len; i++) {
  filter.block.add(blacklist[i]);
}

About this article

Published inDev.Opera
DateDecember 6, 2011
AuthorOpera Software
Tagsextensions API, URL filter
OriginalInternet Archive