Friday, November 09, 2007

<CustomAcion>/<UrlAction> and opening a link in a new window

The <customelement> element lets you build a custom menu item for various SharePoint UIs and you can easily deploy your menus using Feature framework.

If you need to include a custom hyper link - You need to use - The problem with is that there is no attribute to open it in a new window - There is no equivalent of "target" attribute of an Anchor - I guess whoever designed this feature must have thought hmmm...since there are lot of pop-blockers who would want to open a hyper link in a new window - So why bother putting this feature :) Well pop-blocker are good for blocking ad windows but at a time you do want to open a link in a new window for usability purpose -

So in order to open a link in a new window you can use the good old javascript:window.open(url)

e.g.

<urlaction url="javascript:window.open('url')" >



What is wrong with the above line ???

Well, the above line works when deployed in SharePoint - The target link in fact does opened in in a new window but while IE opens the link in a new window, it also replaces the current window with [Object] message (IE tries to open the javascript as a link in the current window) - This is pretty annoying - You need to click the back button to go back to the previous screen in the current window...

How to solve the problem in IE ?

Well , you can trick IE to think this is not a window.open() command and you are executing a custom script - So just replace the above url with something like


<urlaction url="javasscript:void window.open('url')">


And now IE will only open the link in a new window -

I hope Microsoft fixes this during SP1 time frame by providing a "target" attribute on UrlAction element




3 comments:

Jexter said...

You rock. Was doing exactly the same thing, add void infront of call, works like a charm!

Thx amn

Jexter said...

You rock. Was doing exactly the same thing, add void infront of call, works like a charm!

Thx

Z-Woman said...

I can't get the code to work... I'm reading in the Step by Step Microsoft Windows SharePoint Services 3.0 book on page 29 that I should be able to open the link up for editing and add javascript:void(window.open('url')) and that should work and I've tried your suggested code - I'm addding your code right in the the Links URL box...??