Force link to open in a new tab using target=_blank

Hi, I am using the following vb.net code to populate a submenu item (which works properly) but it does not open a link in a new tab. How do I do this using target=_blank ?

Dim oMenuItem As Syncfusion.JavaScript.Web.MenuItem

mnuLinks.Items.Clear()

conn.ConnectionString = AccessConnect

conn.Open()

myCommand.Connection = conn

sSql = "SELECT * FROM Links"

myCommand.CommandText = sSql

myReader = myCommand.ExecuteReader

If myReader.HasRows Then

While myReader.Read()

oMenuItem = New Syncfusion.JavaScript.Web.MenuItem

oMenuItem.Text = myReader.Item(2).ToString

oMenuItem.Url = myReader.Item(1).ToString

oMenuItem.HtmlAttributes = ""

'oMenuItem.LinkAttributes.Insert(0, "target=_blank") <--- this does not work so is commented out

mnuLinks.Items.Add(oMenuItem)

End While

Else

oMenuItem = New Syncfusion.JavaScript.Web.MenuItem

oMenuItem.Text = "*** No Skittles Links Found ***"

mnuLinks.Items.Add(oMenuItem)

End If

myReader.Close()

myReader = Nothing

myCommand.Dispose()

conn.Close()

conn.Dispose()

Many thanks for your help, John



1 Reply 1 reply marked as answer

SS Sivakumar ShunmugaSundaram Syncfusion Team December 27, 2022 12:56 PM UTC

Hi John,


Greetings from Syncfusion support.


To open a link in a new tab using our Menu component, you can use the LinkAttributes attribute as follows:


Refer to the below code snippet.

[Default.aspx],

 

<ej:Menu ID="weblink" Width="600" runat="server">

 

    <Items>

 

        <ej:MenuItem Id="searchengine" Text="Search engine">

 

            <Items>

 

               <ej:MenuItem Text="Bing" Url=http://www.bing.com/ LinkAttributes="target:'_blank'"></ej:MenuItem>

 

            </Items>

 

            <Items>

 

                <ej:MenuItem Text="Google" Url=https://www.google.co.in/ LinkAttributes="target:'_blank'"></ej:MenuItem>

 

            </Items>

 

            <Items>

 

                <ej:MenuItem Text="Yahoo" Url=http://in.yahoo.com/ LinkAttributes="target:'_blank'"></ej:MenuItem>

 

            </Items>

 

...

 

    </Items>

 

</ej:Menu>


This attribute allows you to define the target of the link, in this case, a new tab.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication1344589319.zip


Check out the attached sample for your reference.


Marked as answer
Loader.
Up arrow icon