Raj
Raj

Reputation: 374

Open calculated link from view column on an new window/tab in x pages

I am trying to open a view column link into new window or tab. I am not able to get through. I have used numerous ways like mentioned in some of the pages under same category. Here is my sample code.

<xp:viewColumn columnName="$5" id="viewColumn1"displayAs="link">
    <xp:this.pageUrl><![CDATA[#{javascript:try{
    var row = getComponent("viewPanel1").getChildren().toArray();
    var va= row[5].getValue();
    var href = "some html page";
    return href+"?confId="+va;
    }catch(e){

    }
    }]]></xp:this.pageUrl>

I have used below code to work around

<xp:viewColumn columnName="fname" id="viewColumn1" displayAs="hidden">
    <xp:link escape="true" target="_blank">
        <xp:this.text><![CDATA[#{javascript:try{view1.getColumnValue("lname");}catch(e)   {}}]]></xp:this.text>
        <xp:this.value><![CDATA[#{javascript:try{thisid = view1.getColumnValue("lname");
   var calculatedlink = "www.google.com";
   return calculatedlink}catch(e){}}]]></xp:this.value>
    </xp:link>
    <xp:viewColumnHeader value="First Name" id="viewColumnHeader1">
    </xp:viewColumnHeader>
</xp:viewColumn>

Upvotes: 0

Views: 1655

Answers (1)

stwissel
stwissel

Reputation: 20384

Raj, as a user I'm not pleased if you decide when to open a new tab or window. I do that (it is my browser after all). So you might consider your forced window opening. But if you have to....

Split the functionality: make a regular link, give the links a css class. Then use XSP.addOnLoad(...) to add target="_blank" to all the links with that css class. Keeps your code lean and makes it easy to remove.

It also opens the possibility to offer users a config option (to be stored in a cookie) if they want the new windows or not.

Let us know how it goes. :-) stw

Upvotes: 2

Related Questions