Automatic random URL redirect - javascript

So I have a website on Google Sites, and I want to add a 'random post/page' button. I found this code on GitHub and edited it by putting my own URL's. Everything works according to plan except the code uses cookies, basically you go to the link once, it redirects you to a random URL that you have chosen, and it saves that URL. I want to make it so that it's always random, no cookies. I've tried altering the code but nothing seems to work since I don't know much about code, except for the basics. Could anyone help remove the use of cookies of this code? You can view the code below. Thank you.
This is the GitHub code
I tried deleting any code that I thought could be related to the cookies, basically the bottom of the code. The code still worked, but the cookies we're still saving. Like I said, I only know the basics so I was just deleting and praying it would fix it.

Can be massively simplified if you don't need the cookie functionality:
const redirectUrls = [
"http://www.aftonbladet.se/",
"http://www.dn.se/",
"http://www.svd.se/",
]
document.location = redirectUrls[Math.floor(Math.random() * redirectUrls.length)]

Related

URL address changing from localhost:3000/home to localhost:3000/home#_=_

I configured my project first with passport-google-oauth20 authentication and it was working fine.
I added the passport-facebook after that and its working fine as well, however, after logging/registering with my FB account my redirecting URI which is supposed to be "http://localhost:3000/home" shows "http://localhost:3000/home#=" instead. It isn't showing any errors in the console and also working as it is intended to. I've got no clue what part of code I'm suppose to share with you guys as the functionality of the project is intact, so please let me know the snippet which may help you to better understand the issue.
This is not a problem itself.
https://github.com/jaredhanson/passport-facebook#why-is-__-appended-to-the-redirect-uri

`window.location.href` not working as intended

I'm using a JavaScript, along with PHP, to create a login system for a project I'm working on.
I have everything working in regards to actually logging the user in, and then checking this within my JavaScript. However when I redirect the user from the login page to a private page, I'm having issues with window.location.href in the JavaScript.
I own the domain thomas-smyth.co.uk, so I have tried the following piece of code to redirect the user.
window.location.href = "http://thomas-smyth.co.uk/home.php";
However, when this redirects me, it is redirecting me to thomas.smyth.co.uk, which obviously causes the page not to load. Any ideas on how I could fix this?
Thanks in advance,
Tom
You have posted the wrong code. In your Js File thomas-smyth.co.uk/functions/login.js on your webserver is this:
//Re-directs to subdomain.
window.location.href = "http://www.thomas.smyth.co.uk/home.php";
this should be fixed to
//Re-directs to subdomain.
window.location.href = "http://thomas-smyth.co.uk/home.php";
#vlaz mentioned right, you have a second mistake with a wrong dot instead of a dash
And btw you should explain your problem a bit more. More code would be usefull next time if you want some help.

I want a codes which redirect to my website when JavaScript used on wrong site

I want to secure JavaScript Codes. I secure my JavaScript with https://javascriptobfuscator.com/ but it can also stolen from view source.
I want a codes which redirect to my website when JavaScript used on wrong site.
This is possible I know but I don't know how?
What you could do is check the return of location.host or location.hostname.
To redirect to another URL you would change the value of location:
location = "https://mywebsite.com";
//or alternatively
location.assign("https://mywebsite.com");
However, the redirection may will be prevented by Cross-origin resource sharing policies (see Michael's comment). So you could just display an alert dialog.
alert("Don't use my script on your website");
The person trying to use your code on their website will be warned during development by this alert.
In any case, your obfuscated code can still be changed and someone that is determined will remove these "security" measures and it can even be deobfuscated.
Are you sure all of this is needed ? Modifying a stolen code to make it work on another website can be harder/longer than just rewriting a similar code. Apart if you are doing something very special and new, I think you are just losing time by trying to protect your code.

appMobi / phonegap setting/deleting cookie click action required 2 times before working?

I can't figure out for the life of me whats up with this. I dunno if this is appMobi/phonegap centric, cause they have there own special ways of setting cookies, and handling them. But I have what seems to be a unique problem overall, and it only occurs in the process of actually writing a cookie for the first time. Or removing it if it exists which is kind of like writing it.
Anyway I have 2 functions that worked perfectly up til the point of introducing the cookies to them. But I need the cookies also as its part of a login check, and a handful of other things. So this is my issue.
I type my user/pass, hit login. get nothing. hit login again, works.
I hit logout after being logged in, nothing works. hit it again.. works..
These are ajax driven functions as well. Dunno if that has anything to do with it or not, but in both cases cookies are being written in one shape form or another and thats when the functions seem to break in respect to the fact that I need to click the buttons that trigger them twice to get the desired effect despite them being a single click action.
If I remove the cookie lines from my functions everything works normally again without problem, with exception that the cookies are required to actually use half the stuff I am building. Also its a lone cookie being written with a numeric value.
Ideas?
AppMobi.cache.setCookie('AutoRemember', uid, 90);
This one line if its there, i have to double click for my functions to work, if its not there my functions work as expected..
a sample of one of my function would be (quickly typing one out here for example sake)
$('#buttonX').click(function(){
url = 'http://www.domain.com';
$.post(url, function(data)
{
if(data.status == "good")
{
AppMobi.cache.setCookie('AutoRemember', uid, 90);
window.location = 'dashboard.html';
}
}, 'json')
});
Ah yes, I ran into the same thing. You'll need to download and init the local_bootstrap.js lib and something from "Develop In Eclipse For Android " (I downloaded the .zip "appMobi Cloud Services library for PhoneGap Android development"). I'm doing the Android app with Eclipse, and I assume you are too, your post didn't mention what IDE you were using.
The .zip file has a great readme.txt on where & what to copy (.java files, jar file, etc.)
found here: http://www.appmobi.com/?q=node/85
Well, come to find out or as far as I can figure at least. This appears to be a glitch between browser and emulator more so than it is my coding. When I run the app in the sandboxed appMobi application from "Test Anywhere" things work as expected all around.
I will be opening up a bug ticked on appMobi where every they take bug reports and I will come back here with a link later so others may follow it as well when and if they come across a similar issue.

page area not refreshing using jquery and setinterval

i am trying to refresh a particular area of my php page, which will load the updated information from database. My code are working on localhost. But, when the same code i'm trying to execute on my domain. Then, it is not refreshing and not showing updated information, and i don't why... Anybody have any idea..
setInterval(updateShouts, 10000 );
function updateShouts(){
$('#refresh').load('ajax/check.php');
};
this is the code, which i'm using for refreshing the
.
I'd check that the URL is correct:
You can use Firebug (or another Javascript debugger) to watch the request going out, and you can see if it was a 404 error or if it worked.
Also, in the Console, just type in $('#refresh') and make sure it returns an actual object.
if it just displays [] or undefined, then the selector is wrong.
Try:
function updateShouts()
{
$('#refresh').load('ajax/check.php');
};
setInterval(function(){updateShouts();}, 10000 );
Problem is with most localhost dev servers the configuration, security, etc.. is usually at the load end of the scale vs a host else where. So that may or may not be part of the issue, I couldn't say for sure though
Edit I agree with the notion of checking to make sure the path ajax/check.php is valid also. And that Firebug is a very handy tool to have when developing with jquery (or javascript stand alone)

Categories

Resources