单击更改传出链接的位置

时间:2022-11-21 15:32:13

I'm trying to link to another page without displaying the real URL on hover or in the source code. I want <a> to redirect to $newUrl; even if there is another url defined in the href="".

我正在尝试链接到另一个页面而不显示悬停或源代码中的真实URL。我希望重定向到$ newUrl;即使在href =“”中定义了另一个url。

<?php $newUrl = "http://therealurl.com/folder/private.php" ?>
<a href="http://domain.com">Link</a>

So using the code above I want to replace http://domain.com with <?php echo $newUrl; ?> when the user clicks on the <a> because i never want it to be displayed to the user.

所以使用上面的代码我想用 当用户点击时,因为我从不希望它显示给用户。

Is there a solution to target a specific anchor to do this? If not then every link on the page is fine I just want to do this in a way that the real URL is not displayed for privacy reasons.

是否有针对特定锚点的解决方案来执行此操作?如果没有,那么页面上的每个链接都很好我只想以一种不出于隐私原因显示真实URL的方式这样做。

2 个解决方案

#1


Here is solution.

这是解决方案。

 <?php $newUrl = "http://therealurl.com/folder/private.php"; ?>
 <script>
  $( document ).ready(function(){
  $( '#link' ).click(function(){
        var newLink = <?php echo json_encode($newUrl);?>;
        $(this).attr("href", newLink);
    });
  });
 </script>
 <a id="link" href="http://domain.com">Link</a>

Don't forget to include jquery library.

不要忘记包含jquery库。

#2


If you have full access to the original link, you could use it as a redirect by setting a header in the destination script.

如果您具有对原始链接的完全访问权限,则可以通过在目标脚本中设置标题将其用作重定向。

header("Location: yoururl.php);

This is the only quick easy solution that I can think of, as this one will not show the actual destination in the source code.

这是我能想到的唯一快速简便的解决方案,因为这个解决方案不会在源代码中显示实际目的地。

If you want to hide the link from the source code then any javascript methods won't work, to my knowledge.

如果你想隐藏源代码中的链接,那么据我所知,任何javascript方法都行不通。

You could also use ?page=get stuff to change where it sends the user, in order to make this script usable in multiple ways, just don't forget to manage your GET data safely.

您还可以使用?page = get stuff来更改发送用户的位置,以便使此脚本可以多种方式使用,只是不要忘记安全地管理您的GET数据。

#1


Here is solution.

这是解决方案。

 <?php $newUrl = "http://therealurl.com/folder/private.php"; ?>
 <script>
  $( document ).ready(function(){
  $( '#link' ).click(function(){
        var newLink = <?php echo json_encode($newUrl);?>;
        $(this).attr("href", newLink);
    });
  });
 </script>
 <a id="link" href="http://domain.com">Link</a>

Don't forget to include jquery library.

不要忘记包含jquery库。

#2


If you have full access to the original link, you could use it as a redirect by setting a header in the destination script.

如果您具有对原始链接的完全访问权限,则可以通过在目标脚本中设置标题将其用作重定向。

header("Location: yoururl.php);

This is the only quick easy solution that I can think of, as this one will not show the actual destination in the source code.

这是我能想到的唯一快速简便的解决方案,因为这个解决方案不会在源代码中显示实际目的地。

If you want to hide the link from the source code then any javascript methods won't work, to my knowledge.

如果你想隐藏源代码中的链接,那么据我所知,任何javascript方法都行不通。

You could also use ?page=get stuff to change where it sends the user, in order to make this script usable in multiple ways, just don't forget to manage your GET data safely.

您还可以使用?page = get stuff来更改发送用户的位置,以便使此脚本可以多种方式使用,只是不要忘记安全地管理您的GET数据。