How to send data across domain using javascript and tampermonkey? - javascript

I follow a forum where people post many links. I've made a script, using javascript and tampermonkey (chrome extension), that first opens all unread thread in new tabs, than it looks for unread posts that have links and opens those links in new tabs.
This script saves me a lot of time and it is working pretty well. Nevertheless, I would like to improve it.
I want to change the title of the page that has been just opened in order for it to show the name of the thread on which the link that sent to this page was. For example:
On the thread "Fruits" there is a link that opens a new tab to a website "www.apple.com". I would like to change the tittle of this page to "Fruits - The name of the page", so I can know from which thread this link comes.
I use localstorage and sessionstorage to send information from one page to another page when my script is navigating inside the forum domain, but I have no idea what I can use to send information across different domains.
Furthermore, I would like to know if there is a way to tell tampermonkey to run the script according to the link that was opened.
I do know how to change the tittle of the page, the problem is taking the name of the thread that is on the forum domain and using it to change the tittle on the new tab that is on a domain different from the forum domain.

Localstorage doesn't allow access on different domain. You need to store that data in database server. The easiest is to sign up a database service, and it provides API you can use. If you're going to host your own, you must write your own scripts that allow CORS to provide the access to database server.

Related

Hosting a Javascript Source File on to Firebase

I am new to Firebase and thus I am asking this question. Also, I searched something similar to this question, tried them but failed. Thus when writing the reply, it would be great, if someone can add even the significance of the steps.
I have developed a chatbot and code at the following url being loaded when I use the web widget provided by the framework:
http://www.buildquickbots.com/botwidget/v2/demo/static/js/sdk.js
Every time user clicks on the webwidget, the above url gets opened which I doesn't want to happen. Thus I planned to host the code at the above url on to Firebase so that when user clicks on the widget something like myapp.fireabse.com/botwidget/v2/demo/static/js/sdk.js opens up.
How can I do this with nodejs backend?
The sdk.js URL which creates an iframe and appends it your website in a widget. And this domain name is only visible only if you inspect the browser. Check Liva widget: http://www.livafluidfashion.com/
Solution 1:
If you want to see the domain name as myapp.fireabse.com then redirect the incoming traffic from "myapp.fireabse.com/botwidget/*" to "www.buildquickbots.com/botwidget/".
Solution 2:
You can get "firebase.buildquickbots.com" as a domain name also. For that, you have to talk/mail to Gupshup support people.

Restrict Access to a page in a Wordpress website only for specific referrer

I would like to restrect access to one page in a wordpress website, so that the page is only accessible to users coming from a specific website.
Lets say my wordpress website is www.wptest.com and the page www.wptest/tickets should be accessible only to the users coming from the website www.eventorganisatortest.com/register
How is that possible with Javascript? I have a solution with php, but I would like a javascript one. I know, it could be easily spoofed, but it doesn't matter, as our users are not that experienced, and even if they do it, it's not a big deal.. We just make our effort so that they register first on the www.eventorganistortest.com website and click on the button "Buy Tickets" on it, to get redirected to our portal www.wptest/tickets and buy their tickets.
Here is the php code that could do that actually..
PHP Allow access to specific referrer url/page only
You would restrict them using the below code and a conditional.
string = document.referrer;
https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer

Javascript - get click another site page link?

I want to know if my website user click in a link in another website so I can show him a thank you message.
I want to get this click in another website link. Is it possible? How can I do something like this?
Thank you
Your question doesn't state whether you control the link you are trying to monitor, or if you are trying to monitor a link controlled by a third-party website. I'm going to assume the later, but if you control the link, then see the first comment to your answer.
The short version is that there is no way to independently monitor a user's action on another website from within your own. To allow this would violate some of the fundamental tenants that networking and the Internet are based on. For example, if I host the website www.reallyCoolRocksToBuy.com and I want to know whether or not you just purchased a really cool rock on Amazon after viewing it on my site, there is no way to directly get this data even though both my website and Amazon's are open in your browser at the same time.
The highest level object you can access via Java or HTML normally (there are always some exceptions) is the Window object of your own page. There used to be a way to have some control over a third-party page that was launched in a window that you spawned, but this is no longer possible, and even it it was, you still wouldn't be able to monitor any links from that site.
The only way to achieve what you want is for the third-party site to be involved in the communication. Many sites have APIs for sending and receiving referral or link information. For example, Amazon has an API that you can use when someone clicks on an Amazon link from your site. There are a number of ways this is achieved, but basically your link sends a specially encoded string to Amazon identifying your site as the referrer. Amazon can this use this string to create and share session information from the visitor. Depending on what your relationship was with Amazon, you might be able to use this session information to find out if your user purchased a pretty rock from Amazon, but it would be entirely up to Amazon to share this information.
Cookies and other local data can also be used to achieve similar results, but again, you have to have the cooperation of the site.

Javascript communication between two web applications on different domains

I have a web app, which is launched in a new pop-up window when a customer clicks a link on a Drupal web content page.
When the user reaches a certain page in the web application's workflow, I want to send a message to the (still open) Drupal page and pass it some information (like where in the workflow I'm up to).
When the Drupal website receives this 'message', it calls some javascript on its end to update the currently displayed page content.
So basically, a way to execute Javascript on one domain, from a Javascript function in another domain.
I have control over both the Drupal site and the web application so any javascript which needs to be deployed on either end isn't an issue. But note that the two sites are on different domains, so I need to implement something that will work cross-domain
I am not sure how to implement this, I have considered JSON-P so far.
Both your web apps are running at client-side, so you don't need to ask to server about how to contact with the window that you already opened.
So, to save time and effort, make a directly comunication between the windows at client-side.
To send a message to another html page, you need to first keep in a variable the window opened, as bellow:
// This code is inside the html file that open
// the drupal site.
var windowOpened = window.open("drupalUrl.html");
but, at drupalUrl.html you need to create a global function, so you can call like this:
windowOpened.globalFunction(param1, param2);
As I said, inside the drupalUrl.html you need to create a function:
function globalFunction(param1, param2){
//show your message
}

Google Analytics not tracking clientside redirects

I'm trying to solve a problem with tracking traffic to individual blog posts on a system that uses a javascript redirect system where something somehow break tracking.
The way the system works is as follows:
Permalinks are in the format of domain.com/ab_XXXXXX where ab_XXXXXX is a unique code. That code is parsed by a piece of javascript, which tells the browser to load the individual blog post page. This page has a URL format of blog.html/?cd_XXXXXX_ef=YYYYYY. Here too, XXXXXX and YYYYYY are unique codes which, combined, identify the particular page.
When I load the blog.html/?cd_XXXXXX_ef=YYYYYY URL directly, Google Analytics does seem to track the page and the user shows up in the real-time dashboard as visiting that particular page.
However, when I load the domain.com/ab_XXXXXX URL, the user does not show up in Analytics' real time dashboard, even though the analytics tracking gif gets loaded.
Since the ab_XXXXXX URL is the permalink, Analytics appears to contain no data on individual blog post visits at all.
I'm not the programmer on this system, and at this point I'm not sure what to test or to suggest as changes to the programmers.
My question is: why would Analytics track the user in the one occasion, but not in the other? And what could be done to remedy this?
Does the page ab_XXXXXX actually redirect the user to cd_XXXXXX_ef=YYYYYY or does it simply load the contents of that blog post into the same page? In either case, but particularly the latter, you can simply choose to manually track the page view in your existing Javascript snipped by adding something along the lines of _gaq.push(['_trackPageview', 'blog.html/?cd_XXXXXX_ef=YYYYYY']);

Categories