Jump to content

Search for an simple solution for a "random website/file"


Johann

Recommended Posts

Dear W3C school supporters and friends,

 

I am searching for a simple solution to provide such as a random article or file.Not sure, but I could think about a "list" in a file (a list I could make manual), where a script might select a file name by "accident" and builds a link to this web page.

 

Do you have any idea of how such could be managed for someone with less specific skills in all web issues and languages.Thanks in advanced!

 

 

Link to comment
Share on other sites

Gotcha. That's what I thought, but "accident" kind of threw me off, but possibly that was meant to imply it would be random.

 

Anyway, to the OP, what you're asking for is fairly simple if you look at it in pieces.

 

1) learn about array's. You can manually create a list (for now) and then maybe it could come from a file or database.

2) With that array, you will want to get a random number between 0 and the length of that array. That random number will be the index to use to get a link out of the array.

3) Now that you have that, you can present it on the page, or just set the new location.

 

The other thing is you will likely need an event handler to trigger the random link process described above. Did you want to do it on click of an element or on page load? That is something else you will want to look up.

Link to comment
Share on other sites

Gotcha. That's what I thought, but "accident" kind of threw me off, but possibly that was meant to imply it would be random.

 

Anyway, to the OP, what you're asking for is fairly simple if you look at it in pieces.

 

1) learn about array's. You can manually create a list (for now) and then maybe it could come from a file or database.

2) With that array, you will want to get a random number between 0 and the length of that array. That random number will be the index to use to get a link out of the array.

3) Now that you have that, you can present it on the page, or just set the new location.

 

The other thing is you will likely need an event handler to trigger the random link process described above. Did you want to do it on click of an element or on page load? That is something else you will want to look up.

 

Thanks a lot, Thescientist.

 

1) I know that would be the best, but actually I have ony 3 weeks left to be able to work on internet and plenty things I would like to fix. So I guess I am not able to do so, or better. I have some priorities with my limited time.

2) That's what I thought. Intellectual so far no problem, but no language skill and to less basic knowledge. A file with a list of links, with an ID. A script that generates a number out of the given 1...XX numbers and another function that pics up the link under this ID. The whole leads to a new page open in a browser.The idea is that there is a link (Element?)

"Random Article Kind A" and if you klick it, this page will open.

"Random Article Kind A" and if you klick it, this page will open.

 

A list file with the urls under the category Article Kind A

A list file with the urls under the category Article Kind B

 

That are my naive ideas.

Link to comment
Share on other sites

Dear W3school supporters and friends

 

I could say luck but actually simply generosity, a co-helper had a quick inspiration and we got it.

 

How ever, he was happy about the idea to share it here as well, maybe somebody else searches for such solution and its quite simple (if you know the language):

 

 

a script-file, here called "randomsutta.js"

// list of the random selectable filesvar suttalist=new Array(    "http://zugangzureinsicht.org/html/tipitaka/dn/dn.01.0.bodh.html",    "http://zugangzureinsicht.org/html/tipitaka/dn/dn.02.0.than.html",    "http://zugangzureinsicht.org/html/tipitaka/dn/dn.09.0.than.html",    "http://zugangzureinsicht.org/html/tipitaka/dn/dn.11.0.than.html",    "http://zugangzureinsicht.org/html/tipitaka/dn/dn.12.0.than.html");// sum of linksvar listlength=5;// function to get the random filefunction randomlink(){    var pagetogo=suttalist[Math.floor(listlength*Math.random())];    location.href=pagetogo;    }

And the html file where you place the link /action, here called "randomlink.html"

<html><head><title>Random Test</title></head><body><script type="text/javascript" src="randomsutta.js"></script><a href="javascript:randomlink();">Random Sutta</a></body></html>

Thanks a lot all of you here and I wish that it might be useful for somebody, its a gift.

 

 

 

 

 

 

Link to comment
Share on other sites

fyi, you can get the length of any array like

 

var arrLength = suttalist.length;

 

so it can always be dynamic as you add/remove elements, instead of hardcoding it

Link to comment
Share on other sites

fyi, you can get the length of any array like

var arrLength = suttalist.length;

so it can always be dynamic as you add/remove elements, instead of hardcoding it

Thanks a lot for the hint, thescientist! Actually real great help so its easier to maintain. How ever: Hard-coding, I like that word :-) all very relative.

 

I have trouble imagining a use for a random webpage.

 

It works fine, davej, any you are invited to use it. (You could use it also as a real nice "do your task tool, so you dont't need to think around, should I do this, or would this be more joy... push the link and take your choice) Should be not just to waste time, but maybe to open another door by (there are no) accident.

Random SuttaRandom ArticleRandom Jataka

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...