更改“将图像另存为”的操作以重定向到相应的网页


change action of 'Save Image As' to redirect to appropriate webpage

我正在寻找一种方法来更改人们尝试从我的网站下载小徽标文件时"将图像另存为"的行为。 我不介意他们使用我的徽标,但我更希望从我的实际下载页面获取徽标,因此质量很好。

理想情况下,我希望能够设置一个 css 类,以便我可以将行为应用于特定图像。 我不需要它出现在网站上的每张图片上。

当有人访问您的网站时,图像会下载并保存在缓存文件夹中。

但您可以在您的网站上禁用右键单击鼠标以防止人们保存图像:

<script>
    document.onmousedown=disableclick;
    status="Right Click Disabled";
    function disableclick(event)
    {
      if(event.button==2)
       {
         alert(status);
         return false;    
       }
    }
</script>

但请记住,人们仍然可以访问您的徽标。 但更难。

document.onmousedown=disableclick;
status="Right Click Disabled";
function disableclick(event)
{
  if(event.button==2)
  {
    alert(status);
    return false;    
  }
}
<p>some thing</p>

您可以

阻止右键单击和ctrl + u等,以防止其他人保存您的徽标。您可以将此代码放在头部部分:

<script type="text/javascript">
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
return false;
}
function mousehandler(e){
var myevent = (isNS) ? e : event;
var eventbutton = (isNS) ? myevent.which : myevent.button;
if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
var isCtrl = false;
document.onkeyup=function(e)
{
if(e.which == 17)
isCtrl=false;
}
document.onkeydown=function(e)
{
if(e.which == 17)
isCtrl=true;
if(((e.which == 85) || (e.which == 117) || (e.which == 65) || (e.which == 97) || (e.which == 67) || (e.which == 99)) && isCtrl == true)
{
// alert(‘Keyboard shortcuts are cool!’);
return false;
}
}
</script>