Is it possible to control search bar text of a browser via your website using HTML/PHP/CSS/Javascript or any other language. For example, if I have a website called wwww.mywebsite.com, containing 3 different pages e.g. home, pictures and videos and say for example, if the user goes on pictures page I want the website to detect the user is on the pictures page and then change the text in the search bar to www.mywebsite.com/youareviewingpictures or something.
Not sure if this will make sense but in Pesudo code it will look something like this;
IF current state of www.mywebsite.com page = pictures THEN
Search Bar Text = "www.mywebsite.com/yourareviewingpictures"
ELSE
Search Bar Text = "www.mywebsite.com"
If this is not possible, is it possible to write some code, say for example, on the pictures page which changes the search bar text when the user goes to the picture page.
I hope I have made myself clear, if not, please let me know and I will try explaining a bit better.
Thanks.
edit: What I want to know if, whether its possible to change the URL of a website via a code written inside the website that detects what page user is on and changes the URL accordingly.
For example, say I am on www.google.com and I open the the image page the url will change to something like www.google.com/images however, I want to detect via a code that user is on the image page and change the text of the url to say for example, www.google.com/imagepageopened
You can do this very easily if you change the placeholder or value of input instead of the search bar text. Will serve the purpose.
<script>document.getElementById("searchField").placeholder = window.location.href;</script>
What your are trying to find here is called mod_rewrite
for the .htacess
configuration file in a apache server.It's basically a file can be in the root of every site that has special configurations on that changes server behavior like restricting access to certain files,changing the url to a more user friendly version and the like.
This article gives you in debth explanation of mod_rewrite and htacess in general i suggest you start here.
This can be done using javascript, take a look at the window.history
API:
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
This will cause the URL bar to display http://mozilla.org/bar.html, but won't cause the browser to load bar.html or even check that bar.html exists.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/History_API