This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Add external link to built in menu
#1
Hi,

I tried to add a link to the built in navigation with this javascript:

Code:
$(function(){
$('ul.nav-main').append('<li class="level-1" id="show-schedulers"><span class="a"><i class="icon">⇒</i> Schedulers</span></li>');

$('#show-schedulers').on('vclick', function(e) {
  e.preventDefault();
  window.location = '/scada-vis/schedulers';
});
});

   

It is working, but the page doesn't open in a new window If I click the arrow next to the link.

So I tried to find out how the menu is generatet.
In the core.js i found a function called "renderMenuItem", so I tried it with this code:

Code:
$(function(){
 var t = {
   id:9,
   islevel: 0,
   hasitems: false,
   name: "Schedulers"
    };
 renderMenuItem(null, t);
});

But I don't know how to add an external link.

So the question is: How can I add an external link to the built in menu?
Best regards

forsterm
Reply
#2
You need to check the click target element.

Code:
$(function(){
$('ul.nav-main').append('<li class="level-1" id="show-schedulers"><span class="a"><i class="icon">⇒</i> Schedulers</span></li>');

$('#show-schedulers').on('vclick', function(e) {
   var url = '/scada-vis/schedulers';
   e.preventDefault();
  
   if ($(e.target).hasClass('icon')) {
     window.open(url);
   }
   else {
     window.location = url;
   }
});
});
Reply


Forum Jump: