Get root page url using Javascript - javascript

i am developing facebook application, and i need to get the facebook root page url not iframe, all these methods: document.location,window.location and top.location... return the iframe url ( my hosting server ) not facebook url.
any suggestions ?

Try parent.location.href. It might not work if the iframe isn't coming from the same domain, and if so you will just need to get the request url referrer with your server code.
Edit: To get the current url in PHP try $_SERVER['HTTP_REFERER']

Related

Detect URL and Redirecting URL using Javascript

I have a question on how to detect a domain url using Javascript and redirect url.
My point is to redirect url if the url is not my domain. (Eg. my domain is website.com. if the domain is not website.com, it will redirect to website.com.)
I think this will help me against Httrack or other web copier. This will redirect their url if my file is on their site.
Thank in advance.
You can get the current DOMAIN (without any other paths etc)
window.location.hostname;
You can then 'redirect' to another URL using
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
// Another method for doing redirecting with JavaScript is this:
window.location = "https://stackoverflow.com";
Obviously you'll need to carry out a comparison against your own URL before you carry out the redirect, so :
if (window.location.hostname !== "www.mywebsite.com"){
window.location = "https://www.mywebsite.com";
}

Add a HTTP link to SSL HTTPS page without causing Mixed-Content "Not Secure" error

How can I add un-secured HTTP links on this page without causing the error "Not Secure."?
I have a secured web page with SSL HTTPS.
This web page is a dashboard with 100+ buttons which all contain links of external websites.
Unfortunately, not all of these websites support HTTPS ...common its 2020!
Is there any way to resolve this issue while maintaining the site lock?
Attempt #1
<link rel="ampHtml" href="http://example.com/">
Attempt #2
I used TinyURL to convert my HTTP links into short URLs which have
HTTPS. ...this works for most of the links (which is great!)
The remaining links when clicked have additional Javascript which is
adding URL querystrings to the end of the URLs. These strings apply on
the TinyURL successfully, but does not on the final destination URL.
The only other solutions I can think of (if even possible) is ...
JavaScript to convert specific links onClick to HTTP before opening a new tab and loading the website.
JavaScript to delay the load of the HTTP link.
You can make a redirect page. The most basic way is making a redirection page with JavaScript.
if (window.location.search.includes("?url=")) {
var url = window.location.search.replace("?url=", "");
window.location.replace(url);
}
Basically, what's happening is that it redirects from a secure page to a non-secure page without causing a 'Mixed Content' error. It gets the url parameter from window.location.search and then it redirects to that.

Javascript, change URL origin without page reload

Is it possible to replace the origin of the URL without reloading the page? Say I am at www.example.com, how can I change the URL to be www.foo.com or whatever without reloading the page? I tried using pushState() and replaceState() to no avail. I get an error saying: Failed to execute 'pushState' on 'History': A history state object with URL 'foo.com:4041' cannot be created in a document with origin 'http://example.com:4041' and URL 'http://foo.com:4041/'.
For your information. the two URLS are ones which I generated with my /etc/hosts file, they simply pass to an express server at localhost:4041.
Thanks

How does 301 redirect with MASKING work?

I've been playing with 301 redirection with masking with the purpose of sending newdomain.com to hostingdomain.com without the user noticing (transparent redirection). However all available referrer data seems to be missing. For instance I cannot use:
<?php echo parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); ?>
or
document.getElementById("h1").innerHTML = document.referrer; // nothing
document.getElementById("h1").innerHTML = location; // domain hosting files
They all give me hostingdomain.com's (the domain hosting the files) URL data. Please help me come up with a solution to transparently send my domains to my one hosted domain and be able to grab the original domain's data for use in heading tags and such.

Javascript and redirect Location: header detection

I have an URL of domain1.com, that redirect to an URL of domain2.com with HTTP Location: header method.
Can i, running a javascript page on domain1.com, know the final URL pointing to domain2.com? How?
Thank you in advance.
Unfortunately not, most browsers will not give you this level of access and anyone visiting domain1.com will get redirected before executing any code on the page.
Even if you could execute the javascript from domain1.com and make an ajax request to domain1.com, the webbrowser will redirect the ajax request to domain2.com under the hood and return success without giving you any notification of the redirect.

Categories

Resources