ASP.Net page: Chrome adds a #b to the URL? - javascript

when I open the URL
http://mycomputer/web/Page.aspx?OfflineMode=false&ID=2
Chrome will make it look like:
http://mycomputer/web/Page.aspx?OfflineMode=false&ID=2#b
The problem is that I do javascript reloads via the URL with changed parameters and this is disturbing the process.
Any ideas?

Without seeing the page online to troubleshoot it, I would say save the url as a string and then modify the string. Then trying reloading based on the new string.
Is it always just #b added? And do you have an inner page links?

Related

How to Replace the path name of URL using JavaScript/jQuery?

I am trying to replace the url and load the page.
Example:
URL: http://www.example.com/account/edit
I want to replace this as http://www.example.com/account/add. And load this page.
For that, I tried by using location.pathname.
location.pathname = "/account/add";
When using like above, the add page is displayed. But after that, URL http://www.example.com/account/add is loading. Then the add page is not displayed. I get that page is not found message.
The host name should vary based on running the project. So I want to resolve this without based on host name.
How can I achieve it?
If you want to retain the page in your session history (meaning you want to be able to use the back button to it) use the assign method. Otherwise, you replace.
Replace the current document with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session history, meaning the user won't be able to use the Back button to navigate to it.
http://mdn.beonex.com/en/DOM/window.location.html
window.location.href = "http://www.example.com/account/add";
OR
window.location.replace("http://www.example.com/account/add");
This will redirect to the new page.
Actually you can change your url some other ways like below:
window.location.assign("http://www.mozilla.org"); // or
window.location = "http://www.mozilla.org";

Accessing pushState URL on page load

I'm trying to create a gallery that allow custom url rather than url prefix with hashtag.
For example:
http://www.myportfolio.com/gallery/3
rather than
http://www.myportfolio.com/gallery#3
so far everything is working fine, if I access from http://www.myportfolio.com/gallery I was able to go to the next and previous image with the url updated.
My main issue now is although the url is now dynamic but it still cannot be bookmarked, if I enter http://www.myportfolio.com/gallery/4 to go the 4th image it doesn't work.
Is there a Javascript approach to this or do you need a combination of PHP to redirect the url?
It is possible to use client side JavaScript to handle this, although you'll need to set up the server so that every URL (that isn't for something like an image or script) loads the bootstrap document your SPA runs on. You just need to check location.href when the page loads and then set up the content you want.
That said, doing so is a very bad idea that completely misses the point of using pushState and friends in the first place.
The two points of being able to have a normal URL are that:
Clients where the JavaScript fails still get a useful page
The content for that URL is loaded in the initial page load (so it is available faster)
If you aren't going to take advantage of that, you might as well go back to hashbangs.

How to change the omni-bars value without changing the website? Javascript

I just wanted to know is there any way to change the omni-bars value without redirecting to another page using javascript? Maybe something like omni.value = "changed.net"
window.history.pushState(null, null, "/google.com");
This will change the url without reloading the page. If you did that in the console now the url would change to http://stackoverflow.com/google.com. You can only change the url from the web root. So you can't make it look like a user is at google.com itself.

How do I change content without changing pages (non-hashed URLs)?

I know how to change content of a page using AJAX and remote loading of content. However, take a look at UStream's new layout. Click on any video, and not only does the content change without changing the page itself... but the entire URL changes as well. How is this done?
I know how to do it using the hashtag in a URL, and using JavaScript to detect when the location's hash value has changed. For example, site.com/#!/profile to site.com/#!/settings. Any value after the #! part is loaded remotely.
But UStream doesn't use the hash symbol at all. How is this accomplished? What voodoo is at work here?
You're seeing the HTML5 History API.

Javascript change query string for refresh

I am looking for a way to alter the get query string of an html request using javascript (jquery included) without refreshing the page. This query string would be carried over when refresh. For instance, http://thissite.site/index.html?id=123 would be the original url, then an event happens and id changes to 235. When the page is refreshed, the refreshed link would be http://thissite.site/index.html?id=235.
window.location.search = "?id=" + encodeURIComponent(new_value)
https://developer.mozilla.org/docs/DOM/window.location
https://developer.mozilla.org/docs/JavaScript/Reference/Global_Objects/encodeURIComponent
With HTML 5 you can use the the following pushState function. More info found on How does pushState protect against potential content forgeries?.
I was looking for this as well and saw bandcamp using this for the navigation on http://bandcamp.com/discover

Categories

Resources