Changing URL to something else? - javascript

If I have a site "http://example.com/" is it possible to show in the URL (after loading the page) "bananas" instead of "http://example.com/"?

No, this is not possible without redirecting to another page.

This isnt possible with a redirect. You cant do it anywhere

Closest you can get is window.location.hash = "bananas"; which produces http://example.com/#bananas.

Related

redirect to other html file with parameters

I want to redirect from a.html to b.html with a parameter for example array c[],i used something like location.href = "b.html"; but when i write something like console.log(c[0].name); in my .js i got nothing after the redirection to b.html!
thanks in advance for your help :)
$(".btn").click(function(){
location.href = "b.html";
//.. push of some elemts to the array elements
// .. try to show elements in b.html with console.log() for example
});
As commented before, once you are redirected, you are literally on a new page. So everything you had before is unloaded. ( And your script which is supposed to execute after setting the location.href is stopped )
There are several ways to handle data into the next page, but by far the most easiest one would be to use query-parameter in your URI. Check that out:
https://en.wikipedia.org/wiki/Query_string
You are limited by the size of data, the data is somehow visible, and it could be easily hacked, though - but it seems you are quite at the start of something anyway.(?)

window.location.replace(document.URL) not triggering if url contains '#?' at the end

In my sample website, I was trying to redirect my page using javascript window.location.replace method. As I need to refresh the page, I used document.URL. It works well. But sometimes I noticed that it not working without giving any error. Finally I found that some links adds # in address bar and one of my javascript add a ? to the same. At that time the code window.location.replace(document.URL) wont execute. Is that due to the characters in the URL?
here is my function(sample)
function sample() {
alert(document.URL);
window.location.replace(document.URL);
}
the alert showing url like http://localhost/something/#?. and at this time it will not refresh the page.
Use any of these
location.reload();
window.location.reload();
window.location.href=window.location.href
You need to use location.reload(); instead.

options to navigate from one page to another

Hi I want to navigate from one page to another without ajax. With ajax we can use $.mobile.changePage('test.html') But I am targeting blackberry5+ version. Instead of window.location and <a href="test.html"> is there is any other option available. Any suggestion will be appreciated.
try:
window.location.href = "test.html";
OR:
window.location.assign("test.html");
window.location.replace("test.html");
Not sure I understand but onclick="setLocation('newurl.html');" is another method?

Refresh entire "window"...!

I need to refresh a particular page say every 2 mins. But, only the <iframe> within it gets
refreshed. I tried: window.location, location.href and so on. I need to pass new parameters every time and reload the page. So, think, .reload might not work. Please help.
have you tried:
document.location.reload(true)
or
parent.document.location.reload(true);
You need to access the parent:
parent.location.href = 'blah.html'

Make browser go to different url on button click?

I've got a jquery-ui button. When clicked, I want to move the browser to a url within my domain:
<button onclick='foo'>Go</button>
function foo() {
window.location('/otherpage');
}
is that the right way to do it, and address it relatively? Is there a better way to do this?
Thanks
$('#button-id').click(function() { window.location.pathname = '/otherpage'; });
What do you mean by relatively? To the current page or to the current host? There are a few options you are able to use.
It should be window.location = '/otherpage'; Other than that I think it's fine.

Categories

Resources