How twitter changes url without reloading page? [duplicate] - javascript

This question already has answers here:
How do I modify the URL without reloading the page?
(20 answers)
Closed 6 years ago.
Recently I've noticed that if we are at our profile view/url (http://twitter.com/profileName) and click on one of our tweets to see its details on popup, the url changes (http://twitter.com/profileName/status/statusId) without reloading the page (no # in url used).
With further investigation, I've noticed that window.history changes, from:
{ title: "profileName (#profileName) | Twitter" }
to:
{ inOverlay: true, rollbackCount: 1 }
I'm currently working on own Single Page App stack, and stuck on writing own router - looking forward for alternatives against currently trending # usage and thought that understanding this twitter hack can help me a bit.

They use the HISTORY API:
window.history.pushState("", "", '/newpage');
Reference: https://blog.twitter.com/2012/implementing-pushstate-for-twittercom

Related

How to check if link to image is not broken [duplicate]

This question already has answers here:
Check if image exists on server using JavaScript?
(18 answers)
Closed 2 years ago.
Is there way to check if link to image is working before adding src attribute to image?
What I have tried:
First idea was to make ajax call to image src but I cannot be sure that CORS pocily will allow it.
Adding onError callback into my component. No luck because I use SSR and it causes problems
My use case:
I'm building text editor and user can insert link to image. I want to know if link is ok before inserting it into my model.
The other answers/question aren't specifically about cross-domain requests. If you only have to support modern browsers you can use an opaque fetch request which works cross domain and is pretty easy to use.
fetch('http://example.com/your-image-url', { mode: 'no-cors' }).then(() => {
if (response.ok) {
// the image exists
}
});

Changing subdomain without refreshing the page [duplicate]

This question already has answers here:
how to fully change url without reloading the page to new url?
(2 answers)
Closed 3 years ago.
Is it possible to change change subdomain without refreshing the page?
E.g. from www.somedomain.com to aaa.somedomain.com without full reload?
Edit: I need to switch subdomain part only so in above example somedomain.com stays same, only www is changed to aaa
what you are looking for is History.pushState(), but as described here,
It can't be done. This is by design. There are no exceptions.
From the Mozilla pushState documentation:
The new URL must be of the same origin as the current URL; otherwise, pushState() will throw an exception.

Disable working of browser's back button on logout in jsp [duplicate]

This question already has answers here:
How do we control web page caching, across all browsers?
(29 answers)
Closed 6 years ago.
I am developing a web application using struts2 and jsp. I want to implement logout functionality in it. Although, I am able to remove the session but the browser's back button sends me back to the previously visited pages. I added the following code in each of the jsp file for preventing the caching. But this is not working. Kindly help.. So that after logout one cannot access the pages.
Code :-
<%
response.setHeader("Cache-Control","no-cache"); // HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0);
%>
I have added this code in head tag of each and every jsp page.
You could use JavaScript into your jsp page and use some logic with JSTL to run this script only when it is a logout action.
history.pushState(null, null, '');
window.addEventListener('popstate', function (event) {
history.pushState(null, null, '');
});
It prevents user to back to previous page.

Javascript trigger a URL on Homepage Load [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
We are moving our website from hosting.
I was wondering why the Youama extension is not loading on our homepage. This is our website in old hosting as you can see upon loading the homepage the extension is loaded right away. But in our new hosting which is an exact replica, no changes or modifications added, as you can see it's not loading the extension, but if you click the Login at the top it will run the extension.
Can someone here please help me identify the issue? Or maybe give me a solution wherein I can manually add a Javascript code so I can trigger such event?
Looking forward.
There are hard coded links to the old site, see the example below. Change those links to the new domain.
function isUserLoggedIn()
{
$.ajax({
//Update to http://electricbot.com/lipstickboutique/
url: "http://lipstickboutiquewholesale.co.uk/checkuser.php",
async: false,
cache: false,
timeout: 30000
})
.done(function(data){
userStatus = data;
})
;
}
There is a javascript error that blocks the Youama extension to execute.
Maybe you are still sending ajax request to old url: There is some kind of CORS prevention on the back-end, which results in ajax request failing.

Angularjs link issue in html5Mode [duplicate]

This question already has answers here:
Reloading the page gives wrong GET request with AngularJS HTML5 mode
(23 answers)
Closed 7 years ago.
I am using angularjs , and I am using html5Mode.
Before using html5Mode , links work in both same page and new tab. Link like this:
http://localhost:81/vahidnajafi/#/about
But in html5Mode, it works only in same page, but when I open it in new tab it goes to 404 Not found page.
http://localhost:81/vahidnajafi/about
Thanks.
Your need to redirect or reroute the request to your root url on the server.
Your server returns a 404 before angular gets the chance to do something with that route.

Categories

Resources