Javascript trigger a URL on Homepage Load [closed] - javascript

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.

Related

Cross-Origin resources sharing when i dont have access to the server [duplicate]

This question already has answers here:
No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API
(26 answers)
Closed 4 years ago.
I've been trying to workout if it's possible for me to get rid of my 'Access-Control-Allow-Origin' error.
I'm requesting data from some reports that come back as CSV files but for them to work i have to use a chrome plug in that disables CORS.
after reading tons of stack over flow questions and lots of googling i still can't tell whether it's something I'm not putting in my code or if it's a setting where the data is stored that needs to turn it on.
here is my code that requests the data, bare in mind this works just only with the plug in and my API key has been removed.
function Getfueltype(){
j=JSON.stringify
$.ajax({
url: 'https://api.bmreports.com/BMRS/FUELINSTHHCUR/v1?APIKey=&ServiceType=CSV',
async: false,
success: function (csvd) {
data = $.csv.toArrays(csvd);
},
dataType: "text",
complete: function () {
while (n < (data.length)-2) {
fueltype = j( data[n].slice(1,2));
GigaWatt = j(parseFloat(data[n].slice(2,3)));
arr.push(fueltype);
arr2.push(GigaWatt);
n++
}
drawChart2(data);
}
});
}
If you are attempting this on a local machine to test the code before it goes live on a server, I used --allow-file-access-from-files flag for my chrome.
This allows you to bypass No Access-Control-Allow-Origin header problem.
Example:
Create a copy of chrome.exe in the installation folder.
Send that copy to the desktop as a shortcut.
Right-click on Chrome shortcut and paste the flag at the end of the Target box. (See example string below)
Target - "C:\Users\SuperCoolUser\AppData\Local\Google\Chrome\Application\chrome-copy.exe" --allow-file-access-from-files
Hope that helped even the slightest bit.

Check if a file exists, if not create one, Javascript

I know this question have already been asked. BUT NONE of this,this, this,this,this or this solutions worked for me. I'm only using HTML / CSS / JS for the moment on my website. Later this should run on an apache or IIS server.
Situation :
On my website I wish user to access different servers. I got a html select with a lot of choice. Once they made their choice and click on connection button I check the choice they made and open it (it's a web interface like 127.0.0.1) in a new tab the link.
Problem : Some of the servers should not being accesssed if one is already used.
Example : If 127.0.0.1 is used by someone, no one should access 128.0.0.1 or 129.0.0.1
The solution I found was creating a file when someone access 127.0.0.1. So when someone want to access 128.0.0.1 or 129.0.0.1, I check if the file exists.
If it does exists I don't open the link and show an alert, if it does not exist I create it and open the link in new tab.
Another problem : How can I know when the tab will be closed in order to delete the file ?
Have you got another solution to this problem ?
Thx in advance for helping me, I'm just a beginner in web. No solutions worked for me so far ...
This code help you to detect when user close a tab.
<script>
window.onbeforeunload = function () {
//write your code here
return false;
};
<script>

How twitter changes url without reloading page? [duplicate]

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

Get Meta Data content scripts in chrome extension [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 6 years ago.
Improve this question
I used chrome.tabs to get the meta data in content scripts for chrome extension. but it dosen't work because the chrome.tabs is only used in background script and popup script.
How do I have to do to get the meta data of active page in content scripts?
Thanks.
Since, as you noticed, a content script can't call tabs API, it need to ask something that can to do it.
That something is a background, or even better, event page.
Asking in this case means sending Messages. A message from a content script will be stamped with the Tab object of the page it comes from, so you don't need to look for it.
// Content script
chrome.runtime.sendMessage({action: "getTabDetails"}, function(response) {
// response.id is the tab ID
});
// Event script
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.action === "getTabDetails") {
// Here, sender.tab will be the tab you need; you can pass whatever data
// required back. For example, the ID:
sendResponse({id: sender.tab.id});
}
});

disable (Ctrl+U) keyboard script to prevent view source [duplicate]

This question already has answers here:
How to disable (View Source) and (Ctrl + C ) from my site
(10 answers)
Closed 9 years ago.
I'm looking for disable keyboard script to protect hidden content.
It is not possible. A user will always be able to view your source since he needs to download it in order to render the page.
There are more ways to view source than what you are trying to prevent:
Using firebug
Using wget
Right clicking on content choosing 'view source'
Using the menu option
Via man in the middle
probably more...
This is not very complicated but totally unreliable. Its same with all other Javascript protections.
First the trick (IE incompatible):
function denyKey(event) {
var code = event.keyCode;
if(event.ctrlKey) {
if(code==85)
return false;
}
}
window.addEventListener("keydown", denyKey);
My code is just scratch, it is not cross-browser. This is where to get keyCodes. I did not put much effort in the code since I want to discourage you from using it.
Once you send data to user, he can read the data unless you encrypt them without giving him the key. This means any:
Javascript authentication
Secret loading pages
Javascript "Wait before download..."
Blocked mouse buttons
..can and will be bypassed by the user.
I have a bookmarklet to unblock mouse buttons for example.
That is not possible, even if it was, it would have been a horrible protection. Even I could write a simple script that fetches the source of an arbitrary page. Everything that the client sees, is 'view source'-able (somebody edit that). Only server-side code is safe. Even if it was only possible to view your page through a real browser (but you can't make it so) you'll probably overlook a accelerator key, or other shortcut. If you don't want the client to see some code, don't give it to him! Keep it server-side (and not in a .txt file, that's accessible too) or don't keep it.

Categories

Resources