Project

General

Profile

Using WAnchor as a popup item

Added by John Foster over 10 years ago

Hi

I have a popup menu with an item to open a new browser window/tab. The menu displays OK, but the new window doesn't appear when the item is clicked. This is not a popup-blocker problem.

Can anyone assist?

Thanks

John

Code is:

Wt::WAnchor* makeAnchor()

{

Wt::WAnchor* a = new Wt::WAnchor("http://google.com");

a->setTarget(Wt::TargetNewWindow);;

return a;

}

Wt::WMenu* wmenu = new Wt::WMenu(stack, container);

Wt::WPopupMenu* pop = new Wt::WPopupMenu();

wmenu~~addItem("New")~~>setMenu(pop);

pop->addItem("Google", makeAnchor());


Replies (3)

RE: Using WAnchor as a popup item - Added by Steven Descheemaeker over 10 years ago

I don't think you can do this on a popupmenu:

pop->addItem("Google", makeAnchor());

My guess is that there will be an anchor created in a stackedwidget, like the example in the widgetgalery where the content is switching in the stackedwidget:

http://www.webtoolkit.eu/widgets/navigation/menu

RE: Using WAnchor as a popup item - Added by Alex V over 10 years ago

Steven is correct. You have to add a link to the WMenuItem.

you can do that like this:

wmenu->addItem("New")->setMenu(pop);
Wt::WMenuItem* mItem = new Wt::WMenuItem("Google");
pop->addItem(mItem);

mItem->setLink(Wt::WLink(Wt::WLink::Url, "http://google.com"));
mItem->setLinkTarget(Wt::AnchorTarget::TargetNewWindow);

RE: Using WAnchor as a popup item - Added by John Foster over 10 years ago

Thanks guys.

What is interesting is that the code works like this:

wmenu~~addItem("New")~~>setMenu(pop);

Wt::WMenuItem* mItem = new Wt::WMenuItem("Google");

pop->addItem(mItem);

mItem->setLink(Wt::WLink(Wt::WLink::Url, "http://google.com"));

mItem->setLinkTarget(Wt::AnchorTarget::TargetNewWindow);

But NOT like this:

wmenu~~addItem("New")~~>setMenu(pop);

Wt::WMenuItem* mItem = new Wt::WMenuItem("Google");

mItem->setLink(Wt::WLink(Wt::WLink::Url, "http://google.com"));

mItem->setLinkTarget(Wt::AnchorTarget::TargetNewWindow);

pop->addItem(mItem);

In the latter case, no window/tab is opened. Is this a feature or a bug?

    (1-3/3)