I would like to have Firefox add-on which recognizes a website page and automatically redirects to link in the page identified its XPath.

One example for this is on the news aggregator sites like DZone. Whenever I click a DZone RSS feed's link it goes the DZone website and only after clicking the link it jumps to the actual blog/news page. I want to automatically jump to the actual content/blog/news page when I land the DZone site.


1 Answer 1


Sounds it would be easy to create Greasemonkey userscript to do so.

Greasemonkey scripts are launched only on URLs matching the expreession you provide (so you can write sth like "http://dzone.com/*), and they are executed once page is loaded (top be more more detailed: when DOMContentLoaded event fires).

Writing a script should be easy with just plain JavaScript and XPath. You need to read some value by XPath like you say, and then to do the redirect, set window.location = ....

If I understood you correctly, you can use the following code - works for me in Firefox 7.0.1 / Greasemonkey 0.9.11

// ==UserScript==
// @name           Dzone Automatic Redirect
// @namespace      userscript_dzone
// @include        http://www.dzone.com/links/rss/*
// ==/UserScript==

   var XPathTools = 
      getElementByXpath : function(xpath, referenceNode)
         var xPathResult = document.evaluate (xpath, referenceNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
         return xPathResult.singleNodeValue;

   var xpath = "//div[@id='linkDetails']//div[@class='ldTitle']/a";
   var url = XPathTools.getElementByXpath(xpath,document);
   window.location = url;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .