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?

6
  • Question already been answer!?stackoverflow.com/questions/406192/… Commented Jul 15, 2013 at 20:59
  • I don't see any answer that may help, can you link to that one? Commented Jul 15, 2013 at 21:00
  • look at the bottom right of this page :) Commented Jul 15, 2013 at 21:01
  • Well, no answer is helpful, I only need the path including GET variables, so hashes for example should be ignored. Commented Jul 15, 2013 at 21:03
  • Ok. Do another finding! :) Information is out there! You'll probably need some substring to select the part before the hash stackoverflow.com/questions/9513736/… Commented Jul 15, 2013 at 21:05

2 Answers 2

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;
}
Sign up to request clarification or add additional context in comments.

3 Comments

location.search is exactly what I need. I'll use window.location.pathname + window.location.search thanks :).
glad you got it sorted.
If you're coming here in 2022+ try checking out this stack overflow answer
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

2 Comments

And, what function from window.location can I use to get article.php?id=23 from www.domain.com/article.php?id=23#hash ?
You could use a regex expression if the URL stays consistent

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.