1

I need to get the whole path of page (excluding the domain) so I can show it in an iframe.

I currently use location.pathname to get the path, but the problem is that they may appear GET variables in the URL.

So for a page like article.php?id=23 I get only article.php using location.pathname, thus the page displayed in the iframe is simply a 404 page.

Is there any function to get the path including GET variables?

4

2 回答 2

5

可能没有开箱即用的功能,不。

但是您可以将此作为参考来创建自己的:

Mozilla DOM 参考

具体来说,使用window.location.pathname(如果你不想要它,去掉前导的“/”)并window.location.search获取查询字符串。

IE

function whatIWant()
{
    return  window.location.pathname.substring(1) + window.location.search;
}
于 2013-07-15T21:19:42.663 回答
2
window.location.search.replace( "?", "" );

这将返回获取变量。

链接= http://www.javascriptkit.com/jsref/location.shtml

回答你的问题-> 不,没有任何内置函数,我们必须制作我们的自定义函数并解析它。

获取转义的 URL 参数

于 2013-07-15T21:03:16.600 回答