How to have a project do something based on the user's web address

This is another Javascript code tidbit, but I thought it might be interesting to show how it can be used in Wick specifically. To get a user’s current web address with Javascript, you just need some code like this:

myURL = window.location.href;

To demonstrate how this works, I made this simple Wick project:
detectURL.wick (1.8 KB)

Try opening this Wick project from different versions of Wick Editor:
Normal editor ( editor.wickeditor.com)
Test editor ( test.wickeditor.com)
Alpha editor ( alpha.wickeditor.com)

Each time you run it in a different version, the project will tell you which web address you visited from.

Admittedly this is…only really useful if you’re planning on exporting HTML files and then hosting them on other sites. But even if you don’t end up having a use for it, it’s still kind of neat to know about.

3 Likes

Yes, knowing the url of ur window is pretty neat :D

You can also use window.location without the href

textName.setText('You are visiting from:\n'+window.location);
2 Likes

Oh neat! I just learned something new too :smile:

i tried it on alpha, it didn’t work because alpha was secure (https) and the code used the insecure version (HTTP). i think it’s better to see if the link includes a keyword/phrase instead of the whole link (or use hanzoh’s). very interesting concept anyway :o

1 Like

That’s interesting, when I tried it on alpha it worked for me. And for me, alpha is insecure, it even has a little “not secure” notice in the top left


(I didn’t realize it could vary between users?)
But yeah, checking for a specific word in the URL would probably be better. I’ll try that out.

1 Like

I also have an insecure connection with the alpha editor, I guess it depends on how long you’ve been connected with the editor or something… ?

1 Like

I basically never used the alpha editor before today, so maybe that has something to do with it…I dunno

Here’s a quick update that tests for specific words in the URL rather than the whole URL:
detectURLWords.wick (1.8 KB)
@awc95014 If you don’t mind, I’d be curious to know if you can open it in the alpha editor now, it should only be checking for “alpha.wickeditor” in the URL

works now :slight_smile:

why does the index thing have to be more than -1?

1 Like

That’s just an array thing, if an element doesn’t exist in an array it returns -1.
For example, if you have any array of strings, like this:

myFruits = [“apples”,“oranges”,“bananas”];

And you put in an alert statement like this:

alert(myFruits.indexOf(“pineapples”));

The alert will return -1, because “pineapples” doesn’t exist in the array. (I don’t know why it’s -1 instead of 0, there’s probably some reason but I haven’t researched it before) Edit: I just remembered 0 is the index of the first item in the array, I had a derp moment, sorry. That’s why it’s -1, because there’s no such index in the array. Sorry, I’ve been a half-zombie today because I got like 4 hours of sleep last night

1 Like

nvrmnd…

1 Like

It’s ok, I appreciate you correcting that. I really just had a brain fart there

1 Like

ok it makes sense now!! arrays (and similar stuff) start with an index of 0. myFruits[0] is “apples” because the first item is index 0. that’s probably why it’s -1 when it doesn’t exist.

EDIT: oh wait you said that already oops

2 Likes

It’s all good, sorry for confusing everyone xD (I even confused myself)

2 Likes