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?

XCS
  • 27,244
  • 26
  • 101
  • 151
  • Question already been answer!?http://stackoverflow.com/questions/406192/how-to-get-the-current-url-in-jquery?rq=1 – saamorim Jul 15 '13 at 20:59
  • I don't see any answer that may help, can you link to that one? – XCS Jul 15 '13 at 21:00
  • look at the bottom right of this page :) – saamorim Jul 15 '13 at 21:01
  • Well, no answer is helpful, I only need the path including `GET` variables, so hashes for example should be ignored. – XCS Jul 15 '13 at 21:03
  • Ok. Do another finding! :) Information is out there! You'll probably need some substring to select the part before the hash http://stackoverflow.com/questions/9513736/current-url-without-parameters-hash-https – saamorim Jul 15 '13 at 21:05
  • My question is if `Is there any function to ...` to get what I want directly. – XCS Jul 15 '13 at 21:07

2 Answers2

7

There probably isn't an out of the box function, no.

But you can use this as a reference to create your own:

Mozilla DOM Reference

Specifically, using window.location.pathname (strip the leading "/" if you don't want it) and window.location.search to get the querystring.

i.e

function whatIWant()
{
    return  window.location.pathname.substring(1) + window.location.search;
}
Stephen Byrne
  • 7,400
  • 1
  • 31
  • 51
2
window.location.search.replace( "?", "" );

this will return the get variables.

LINK=http://www.javascriptkit.com/jsref/location.shtml

Answer to your question->no,there is no any built in function ,we have to make our custom function and parse it.

Get escaped URL parameter

Community
  • 1
  • 1
HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
  • And, what function from `window.location` can I use to get `article.php?id=23` from `www.domain.com/article.php?id=23#hash` ? – XCS Jul 15 '13 at 21:04
  • You could use a regex expression if the URL stays consistent – Sri-- Jul 15 '13 at 21:07