Currently, my page URL looks something like so:
https://example.com/eg?page=2
The URL can also sometimes look like:
https://example.com/eg/?page=2
I want to redirect the user to the same page, but without the query string, so that when clicking on a link it will take you to:
https://example.com/eg
I tried using the following href in an anchor tag suggested in this question:
To home
When clicking on the link, it removes the query string like I want when the current page URL is https://example.com/eg/?page=2. However, if the page URL is https://example.com/eg?page=2 it takes me to https://example.com.
Question: Is there some type of directory path (ie url I can use in my href) I can use such that the two above URLs will always remove the query string? I can use javascript, but if a solution without is possible that would be preferred.
Note: I cannot hard code eg into my href url as I'm developing a widget which can sit in different environments, so, eg is subject to change.
A relative link beginning with ? should only modify the query string, so you could use:
Home
Which would direct your example URLs to:
https://example.com/eg?
https://example.com/eg/?
It does include the ? in the final URL, which might not be what you want, but it is a functional option if you don't want to use Javascript.
You can use,
Home
You can also use document.location instead of window.location. But it is not recommended. See here
Apply this script into your a tag.
Home
Related
consider the following code:
<a id="alink" href="http://google.com">google</a>
This is a fairly basic link tag. At the top of my html page I have:
<base href="//localhost/website/" />
This creates a problem, when i click my link it brings me to:
//localhost/website/http://google.com
I do not want this, I want it to bring me to a completely different site(google.com for example). How can I fix this problem?
try this one.
<base href="http://localhost/website/" />
on localhost no need for directory or double slashes // !=link.
The effect of the base tag is global to the document, and the only way to override the effect of is to use absolute URLs.
You can use window.location in JavaScript to get the URL of the page itself, in case the document was retrieved via HTTP. And you could use it to construct absolute URLs.
But It is better to use server-side technologies that let you construct addresses from one or more base addresses. So quite possibly the best approach is to get rid of the tag.
I need to create a link to a web page that contains the character # (%23). However, when the URL gets decoded (resulting in a URL containing #), the character is not recognized and the page is not displayed properly.
When I create a link as follows, the %23 just gets replaced with #. This may be the behaviour of the browser, but how can I stop it and reach the proper URL with the string still URL encoded? I would prefer to do it without JavaScript if it is possible.
click
Browser goes to: http://aWebsite.com/somePath/somePage #myParameter
I want to go to: http://aWebsite.com/somePath/somePage %23myParameter
It sounds like you need to encode it a second time. The "%" will become "%25" so you'll have:
click
Edit:
If you want the "#" to be sent to the server as part of the URL, then it's not going to work. The browser treats that as a bookmark so it is removed from the requested URL. Once the page is loaded, the browser will scroll to that bookmark.
You need to doube encode it:
http://example.com/somePath/somePage %2523myParameter
%25 will resolve in % in the final url
I'm kind of new to HTML and hoping you an help me out.
I am pulling a database field that is a URL into automated emails. However, the URL is coming over as text.
Is there HTML coding that will turn whatever the text is into a URL without having to list the url in the coding (this is impossible, since the URLs are changing all the time)?
Example: one email says http://blahblahblah.com/yourquotes234980
The next email created is http://blahblahblah.com/yourquotes069283
How can that be turned into a URL link automatically?
Simply use the anchor element:
http://blahblahblah.com/yourquotes069283
Would come out as:
http://blahblahblah.com/yourquotes069283
you have to load that variable into a <A HREF> </A HREF> tag so it will look like this
yourvariable or you can add something else here as a name of your link
with variable i refer the variable where you get the email, so it will dinamically work and you don't have to create email tag for each user only you have to call your variable
i hope i helped you :-D
My webpage url looks like this:
http://mywebsite.com/show-index/index?limit=100
Where limit defines the number of items to display.
I'd like to add a 'show more' which would basically add 'more=true' to my current url:
http://mywebsite.com/show-index/index?limit=100&more=true
I've tried this:
href='?more=true'
But it overides the parameter limit.
Is there a simple way to do it without using javscript?
Thanks
The best would be to do it by Ajax.
If you really don't want to, just use a link
<a href="http://mywebsite.com/show-index/index?limit=100&more=true"</a>
On PHP side, if you detect $_GET['more']='true', juste change the limit to limit+100 in the link.
The best would be to add some achor as #Bartdude says to do not have to scroll each time the page is reloaded.
Don't forget to upvote and mark as solved if you find this useful :)
For example:
http://www.example.com/index.html#foo?key=value
When page is loaded, it goes to the bottom of the page. Any clue?
In HTML5 you just need to set the hash to an ID of any DOM node on the page and it should move the page down in the same way as old style page anchors.
Anything after the hash can only be accessed by JavaScript so if you want to get the value of key you will need some JavaScript to do so.
EDIT: Here is a good tutorial for storing and retrieving several attributes from the hash string - http://www.parorrey.com/blog/php-development/get-url-hash-parameters-values-using-javascript-for-php-_request/
You can read about anchor tags but you querystring is the wrong side of the hash. It should read:
http://www.example.com/index.html?key=value#foo