использование JavaScript для маркировки ссылки, как посещается

Вы можете легко использовать вложенную нетерпеливую загрузку следующим образом

$productCategories = ProductCategory::with('products', 'products.productcategory')->get();

Но вы должны рассмотреть возможность повторного использования значения ProductCategory непосредственно в вашем файле VUE. [ 114]

13
задан dougfelt 28 April 2009 в 01:03
поделиться

4 ответа

The only workaround I know of would be something like the following.

Say, your visited links are red:

<a href="#" onclick="someEvent();this.style.color='#ff0000'">link</a>

But that doesn't mean that when the page is reloaded, the links are still marked visited.

To achieve this, I'd suggest give all links IDs, which are of course unique across your entire app, or namespaced per page. In your onclick, you'll trigger another method, which saves the link's ID to a cookie.

The most easiest would be a comma-separated list, which you can split() before reading. Which is what you do when the page is reloaded. When it's split, you iterate over all IDs and set the color on your links.

E.g, using jQuery:

// onclick
function saveID(id) {
  if ($.cookie('idCookie')) {
    $.cookie('idCookie', $.cookie('idCookie') + "," + id);
  } else {
    $.cookie('idCookie', id);
  }
}

// make all links colored
function setVisted() {
  var idArray = $.cookie('idCookie').split(',');
  for (var x=0; x<idArray.length; x++) {
    $('#' + idArray[x]).css('color', '#ff0000');
  }
}

// assign saveID()
$(document).ready(function(){
  $('a').click(function(){
    saveId($(this).attr('id'));
  });
  setVisited();
});

I haven't tested this code, but it should get you started and give you an idea. If you get lucky, it's paste and win. ;-) I also haven't researched how much you can store in a cookie and what the performance implications are, or what other restrictions apply, also see my comments.

3
ответ дан 1 December 2019 в 22:08
поделиться

Примените класс с таким же определением, как и в.

1
ответ дан 1 December 2019 в 22:08
поделиться

Строго говоря, не существует такого понятия, как «посещенное» состояние для отдельных ссылок. Сами URL-адреса интерпретируются браузером как «посещенные». Любые ссылки, указывающие на URL-адрес в истории браузера, получат стилизацию, определенную псевдостилем: visit в вашем CSS.

Вы можете попытаться подделать его, указав расположение скрытого iframe для нужного URL-адреса, но это не заставит текущую страницу перерисовываться, поэтому я сомневаюсь, что вы увидите: посещенные обновления стиля без обновления.

Для второй части вашего вопроса, я бы, вероятно, согласился с ответом Джордана Джонса .

1
ответ дан 1 December 2019 в 22:08
поделиться

Есть ли способ определить стиль браузера a :hibited?

Я бы сказал, что да, поскольку текущий документ посещается, и вы можете найти его цвет ссылки следующим образом: -

alert(mys_getLinkColor(top.location))


function mys_getLinkColor(href) {
var x, body, res=''
x = document.createElement('a')
x.href = href
body = document.getElementsByTagName('body')[0]
body.appendChild(x)
if(x.currentStyle) {
   res = x.currentStyle.color
}
else if(window.getComputedStyle) {
   res = window.getComputedStyle(x,null).color
}
return mys_rgbToHexColor(res) }


function mys_rgbToHexColor(v) { 
// E.g. 'rgb(5,2,11)' converts to "#05020b". All other formats returned unchanged.
var i
v = v.split('(')
if(!v[1]) return v[0]
v = v[1].replace(/ /g, '').replace(/\)/, '')
v = v.split(',')
for(i=0; i<v.length; i++) {
   v[i] = Number(v[i]).toString(16)
   if(v[i].length==1) v[i] = '0' + v[i]
}
return '#'+v.join('')}
0
ответ дан 1 December 2019 в 22:08
поделиться
Другие вопросы по тегам:

Похожие вопросы: