Javascript页面重定向(Javascript Page Redirect)

编程入门 行业动态 更新时间:2024-10-05 13:30:23
Javascript页面重定向(Javascript Page Redirect)

我正在尝试使用此脚本将任何网页重定向到另一个网页,其中包含上一个网页的网址查询。

我试图使用的代码如下:

window.location = "http://www.readability.com/m?url=" + document.URL;

它不起作用,出于什么原因我无法弄清楚。 我不熟悉编码,所以这可能是问题所在。 这有效......

window.location = "http://www.readability.com"

但这不起作用

window.location = "http://www.readability.com/"

Furthmore我正在使用移动浏览器,而不是像chrome这样的东西。 所以它可能只是一个问题,但它可能不是。 感谢您的阅读,并提前感谢您的帮助。

I'm trying to use this script that will redirect any webpage to another webpage with a query including the previous webpage's URL.

The code I'm attempting to use looks as such:

window.location = "http://www.readability.com/m?url=" + document.URL;

It's not working though, for what reason I can't figure out. I'm not to familiar with encoding, so this may be the problem. As this works...

window.location = "http://www.readability.com"

But this does not work

window.location = "http://www.readability.com/"

Furthmore I'm working with a mobile browser, not anything like chrome. So it may just be an issue with that, but it may not be. Thanks for reading, and thanks in advance for any help.

最满意答案

你需要转义URL,否则它将被剪切在第一个&它包含。

window.location = "http://www.readability.com/m?url=" + encodeURIComponent(window.location);

也忽略document.URL并使用更常见且可互操作的window.location 。

You need to escape the URL, otherwise it will be cut on the first & it contains.

window.location = "http://www.readability.com/m?url=" + encodeURIComponent(window.location);

also ignore document.URL and use a more common and interoperable window.location instead.

更多推荐

本文发布于:2023-08-07 12:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   页面   Javascript   Page   Redirect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!