JavaScript 中的 URL 屏蔽

发布于 2024-09-28 04:52:52 字数 386 浏览 12 评论 0原文

我目前有以下 JavaScript 函数,它将获取当前 URL 并将其连接到另一个站点 URL,以将其路由到适当的反馈组:

function sendFeedback() {
    url = window.location.href;
    newwin = window.open('http://www.anothersite.com/home/feedback/?s=' + url, 'Feedback');
}

不确定这是否是正确的术语,但我想屏蔽 窗口中的 URL .open 语句使用当前窗口中的 URL。

我怎样才能用 JavaScript 中的原始 URL 屏蔽 window.open URL?

I currently have the following JavaScript function that will take current URL and concatenate it to another site URL to route it to the appropriate feedback group:

function sendFeedback() {
    url = window.location.href;
    newwin = window.open('http://www.anothersite.com/home/feedback/?s=' + url, 'Feedback');
}

Not sure if this is the proper terminology, but I want to mask the URL in the window.open statement to use the URL from the current window.

How would I be able to mask the window.open URL with the original in JavaScript?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小兔几 2024-10-05 04:52:52

您可以做的事情:

1- 在您网站的文档内的 html 框架中屏蔽外部网站。
(例如 www.mysite.com/shortUrl/

2-发送 Location HTTP 标头(最终将显示真实的 url)

请记住,浏览器会尽力由于网络钓鱼问题而显示真实地址。

Things you could do:

1- Mask the external site in a html frame inside a document from your site.
(for example www.mysite.com/shortUrl/)

2-Send a Location HTTP header (real url will eventually be displayed)

Keep in mind that browsers do their best to show the real address due to phishing concerns.

无言温柔 2024-10-05 04:52:52

如果我想屏蔽 url,即使认为它可以与 javascript 一起使用,我也不会使用 javascript。在这种情况下你不会得到太多好处。

原因很简单:

  • javascript/jQuery = 函数属于客户端(浏览器/您的 PC/DOM)

  • links、url、http 和 headers = 函数属于 Apache。

Apache 始终处于客户端之上的顶层。每当链接被触发到 SampeLink.html 时,Apache 就会醒来并读取该文件,但在 javascript 声明它们之前,链接/url 就已经被拥有了。因此,如果您尝试操作 javascript 脚本中的链接,那么这是毫无意义的,即使它可以工作但很弱。

我会向您介绍这个很棒的方法:.htaccess,您会惊讶于它的强大功能。如果 .htaccess 出现在 SampleLink.html 的父文件夹中,则 Apache 会拒绝 DOM 引擎(您的浏览器)读取文件,直到 Apache 完成读取 .htaccess。

根据您的场景,.htaccess 可以通过重写链接并将“诱饵”链接发送到 DOM 引擎来为您完成一些工作,同时将原始链接/url 隐藏在幕后;如果访问者试图破坏该应用程序或您担心的任何问题,他们将访问 404 页面。

这有点复杂,但它一直让我失望。我用它作为我的“圣经” http://corz.org/serv/tricks/htaccess2.php

I wouldn't use javascript if I wanted to mask url even thought it would work with javascript. You wouldn't get much benefits in that scenario.

The reason is simple:

  • javascript/jQuery = functions belongs to client-side (browswer/your PC/DOM)

  • links, url, http, and headers = functions belongs to Apache.

Apache is always top level above client-side. Whenever link is fired to SampeLink.html, Apache wakes up and reads the file, but links/urls are already owned before javascript could claim them. So, it is kinda of pointless if you tried to manipulate links in your javascript scripts, even though it works but weak.

I'd point you to this awesome approach: .htaccess and you will be surprised how powerful it is. If .htaccess is presented in the parent folder of SampleLink.html, Apache denies the DOM engine (your browser) from reading files until Apache have finished reading .htaccess.

With your scenario, .htaccess can do some work for you by rewriting links and send "decoy" links to the DOM engine, meanwhile keeping the orginial links/urls behind the curtain; and visitors would reach to 404page if they tried to break the app or whatever you are concerned about.

This is a bit complicated, but it never ceased to fail me. I use this as my "bible" http://corz.org/serv/tricks/htaccess2.php.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文