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.
Related
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
}
});
This question already has answers here:
How to identify if a webpage is being loaded inside an iframe or directly into the browser window?
(18 answers)
Closed 5 years ago.
there is a web app. It suppouse to be avilable only in specific iframe (corp. site), so uninvited guests are redirect to clients web site by script.
Code below is working, but java could be disable in browser. IP white list would be a great solution, but too many dynamic IP is used.
What php trick can be used to check is site opened in iframe?
<script>
if (top === self) window.location.replace('http://uninvited-guests-go.here');
</script>
<?php header('X-Frame-Options: ALLOW-FROM https://iframe.allow.only'); ?>
PHP has no way of knowing what's happening in the browser, but as you've noted, javascript can dependably determine the existence of an iframe with
window.top === window.self;
If you are set on using a pure PHP solution, you could send a GET parameter through in your URL, to tell PHP which guests are invited, and which aren't.
<?php
// yousite.com <-- uninvited user
// yoursite.com?invited=1 <-- invited user
if (isset($_GET['invited']) && $_GET['invited'] === 1) {
// handle your invited guests here
}
You'll also need to add this GET param to your iFrame source.
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
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.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
IE has empty document.referrer after a location.replace
Hi there,
I have got an issue on using the document.referrer property in IE. When I get to a page not through a link but changing the window.location through JavaScript, the document.referrer of the destination page is empty in IE7/8. Any idea on how to get around it?
Thanks.
Store the old page url in a cookie.
Or add the referer to the url in the fragment identifier.
location.href = 'page.html' + '#' + location.href
Or create a link on the fly with javascript, and call it's .click(). So something like
var a = document.createElement('a');
a.href='page.html';
document.body.appendChild(a);//not sure if this is needed
a.click();