HyperLink in Expression

  • 18 September 2019
  • 5 replies
  • 200 views

Userlevel 3
Badge +16

Hi,

 

In K2 5.3, i have a data label with an expression.

In the expression I have a hyperlink operator and add the URL

 

On runtime, if you click the link, it opens on the page you clicked on, i want it to POP out a new window but can't get this to work properly.

 

Any code that will do this? Must be a pop-out window, not a new tab

 

Any suggestions appreciated.


5 replies

Hi Sharpharp,


 


You may find the following links to be helpful in building your expression:


 


https://stackoverflow.com/questions/3219325/javascript-jquery-open-current-link-in-pop-up-window


https://www.w3schools.com/howto/howto_css_modals.asp


 


Thanks!


 

Badge +6

Hi Sharpharp,


 


To build out the expression specifically, you will want to use the Html Decode operator and form your expression as follows:


 


Html Decode(<a href="https://www.google.com/" onclick="return !window.open(this.href, 'Google', 'width=500,height=500')" target="_blank">Google</a>)


 


Note that when you load this into a data label, make sure the data label has in the properties 'Literal' checked and 'Prevent XSS' unchecked. This should let you create the links you need to open in pop up windows.


 


The specific code above has a window.open call which may return false due to ad blockers, which is why it is negated to return true in the event this happens. This will allow the link to still open in another tab/window if an ad blocker is in place.




K2 will not accept any liability for any issues arising from actions taken in respect of the information provided by any forum member. Please kudo my post if it's helpful, or mark as the solution if it answers your query.

Badge +9

Hi Sharpharp1


 


see the link below:


https://community.k2.com/t5/K2-Blackpearl-Forum-Posts/hyperlink-expression-with-Javasrcipt/m-p/78457


 


Regards


Elvis

Userlevel 3
Badge +16

Thanks for the replies,

 

Jared - that decode kinda works, but the IE pop-up blocker brings up a warning.

Is there a way to prevent the warning and have the link appear in Blue, pop out a full screen with menus, toolbars and editable URL.

 

The decode script prevents the user from changing the URL when open (which is cool), but i'd want it just like any other IE window.

 

Any ideas, or would you suggest a different script?

Userlevel 5
Badge +16

Hi Sharpharp1

Could you please attach a screenshot of the warning as I don't see it on my side?


 


 

Reply