JQuery UI tab for _blank webpage

In our format, some pages should be in tabs, which is good. But some of them should be open on a blank page ...

Here is the html;

<div id="tablar">
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">TΓΌm Liste</a></li>
            <li><a rel="ex" href="gtl.aspx?EventId=2">Yeni Ekle</a></li>
            <li><a href="#tabs-2">DetaylΔ± Arama</a></li>
            <li><a rel="ex" href="RaporGtl.aspx">Raporla</a></li>
        </ul>
        <div id="tabs-1">...

So how can I do this. I tried;

$('#tablar #tabs ul li a').filter(function() {
    return $(this).attr('rel') == 'ex';
})
.unbind()
.click(function(e) {
    location.href = this.href;
    e.preventDefault();
});

But does not work ...

which turns # ui-tabs-2 into an address bar ...

+3
source share
1 answer

You're right, jquery will add a hash no matter what, but you can get around it:

HTML

<div id="tabs">
     <ul>
       <li id="li1"><a href="#tab-1">tab1</a></li>
       <li><a href="#tab-2">tab2</a></li>
       <li><a href="#l-http://www.google.com">google</a></li>
    </ul>
    <div id="tab-1">Tab 1 Content</div>
    <div id="tab-2">Tab 2 Content</div>
  </div>

Javascript

$(function() {
  $('#tabs').tabs({
    select: function(e, ui) {
      if( $(ui.tab).attr('href').indexOf('#l-') == 0 ) {
          window.location.href = $(ui.tab).attr('href').substring(3);
      }
    }
  });
});​​

Basically, we say that any link with href starting with C # l- will be the actual link that will follow. Cool, huh? Of course, you could do whatever you want in the if statement, I just added hard forwarding.

0
source

Source: https://habr.com/ru/post/1746819/


All Articles