On 2011-06-01, John Robson <[email protected]> wrote:
> WAnchor *a = new WAnchor("", "text");

> a->setRefInternalPath("LinkName");
> a->clicked().connect(this, &WtApplication::clickLink);

> void clickLink() {
> .....
> }

Hm, the '.....' should somehow scroll the page to the named anchor?

I tried it - with mixed results (firefox 3.6, chromium), here is the
code, and then follows some comments:

#include <Wt/WApplication>
#include <Wt/WLogger>
#include <Wt/WAnchor>
#include <Wt/WText>

using namespace Wt;
using namespace std;

class Main : public WApplication {
  private:
    WText *named_;
  public:
    Main(const WEnvironment &e)
      : WApplication(e)
    {
       log("info") << "Constructing new session";
       WAnchor *x = new WAnchor("", "Jump to the middle", root());
       x->setRefInternalPath("#my_anchor"); // XXX # is not displayed 
       x->clicked().connect(this, &Main::clicked);

       for (size_t i = 0; i < 500; ++i) {
         WContainerWidget *a = new WContainerWidget(root());
         WText *t = new WText(a);
         t->setText("Hello World");
       }
       named_ = new WText(root());
       named_->setTextFormat(XHTMLUnsafeText);
       named_->setText("<div><a name=\"my_anchor\"/></div>");
       for (size_t i = 0; i < 500; ++i) {
         WContainerWidget *a = new WContainerWidget(root());
         WText *t = new WText(a);
         t->setText("end");
       }
    }
    void clicked()
    {
      log("info") << "got clicked!";
      // XXX Now how to scroll to the middle? 
      named_->show();
    }

};

Wt::WApplication *create_app(const Wt::WEnvironment& env)
{
  return new Main(env);
}

int main(int argc, char **argv)
{
  return WRun(argc, argv, &create_app);
}


- In Firefox 3.6 when hovering over the link the browser displays
  'http://127.0.0.1:8080/my_anchor' - clicking on it leads to
  'http://127.0.0.1:8080/#my_anchor' and the browser jumps to the named
  link.

  But I suspect that this is just a side-effect of the used url scheme

- in Chromium the hovering displays the same url, but clicking on it
  leads to a newly created  session (== a reload) - after the reload
  'http://127.0.0.1:8080/my_anchor' is displayed in the url-bar

- Looking at the html code inside chromium ('inspect element') yields
  503 matches of 'my_anchor' - why? Inside firefox ('View selection
  source') the '<a name="my_anchor"/> is also duplicated several times
  when looking at the source

Best regards
Georg


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to