Show url display in bottom-left by JS?

独自空忆成欢 提交于 2019-12-20 02:40:32

问题


Is there any trick to displaying url on bottom left of page by Javascript ?

Example my link element is :

<div data-link="http://stackoverflow.com"></div>

JS :

$(document).on('click','[data-link]',function(){
    var url = $(this).attr('data-link');
    window.open(url,'_blank');
}).on('mouseover','[data-link]',function(){
    var a = document.createElement('a');
    a.href = $(this).attr('data-link');
    $(a).trigger('mouseover');
    // Nothing showing
});

Possible ? Any trick ?


回答1:


As far as I know this is not possible with Javascript, this is a browser-specific function that only triggers when your mouse hovers over a link. If you trigger the .hover() with JS, it "only" applies the CSS-Rules and fires the JS-Functions.

You could create an absolute positioned div with the link-tag and show this when you hover over an element, but it could cause problems when you hover over an actual A-Tag, then your div will get hidden under the browser-field.




回答2:


Is this what you are looking for?

$('a').mouseover(function() {
    var url = $(this).attr('href');
    var style = "position: fixed; left: 0; bottom: 0; z-index: 1000000;";
    $('body').append("<b id='urlDisplay' style='" + style + "'>" + url + "</b>");
});
$('a').mouseout(function() { $('#urlDisplay').remove(); });

Make it prettier by putting the css elsewhere!



来源:https://stackoverflow.com/questions/37341986/show-url-display-in-bottom-left-by-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!