Open random .html file when pressing Shuffle button

50 views Asked by At

My problem is that i have already made implementation of java script Shuffle button but only working in specific url which i will put into line document.location.href i used for this example somefile.html.

    jQuery('body').on('click', '#shuffle-button', function() {
        gtag('event', 'Shuffle', {
            'click': 'true'
        });
        ga('send', 'event', 'Shuffle', 'click', 'true');
        document.location.href = '**/somefile.html**';
    }).on('click', '#station-share-toggle, #station-share-close', function() {
        $('#station-share-buttons').toggle();
    }).on('click', '.jp-share-button', function() {
        window.open($(this).attr('href'), "share", "width=500, height=500");
        return false;
    });

So into same folder where is located somefile.html there is 350+ other .html files which i would like to make it when Shuffle button is clicked to transfer to random of that 350+ .html files. This example only work for somefile.html. What i have to do to or where is my mistake I would be glad if someone has option to make it functional.

I found way to solve my problem I used the same line document.location.href = 'somefile.html' and in somefile.html when someone click then redirects the user (i.e., the web browser) to a random URL from a custom list of URLs.

Into file i used this lines:

<pre>
        var RedirectURLs = {
            "urls" : [
                { "url" : "http://www.example.com/1.html" },
                { "url" : "http://www.example.com/2.html" },
                { "url" : "http://www.example.com/3.html" }
            ]
        }
</pre>

The user is then automatically and randomly assigned to one of the URLs when the user visits this file. HTML file with JS. Thanks to all of you guys!

1

There are 1 answers

0
guest271314 On

This example only work for somefile.html.

You'll have to refer to the same script and include the same HTML in your N HTML files.

Technically all of the files in the folder can be written to navigator.strorage, once, then the user doesn't have to request the files more than once when your Web page first runs - until they clear browsing data for that origin.

Then you can get the file(s) from navigator.storage.getDirectory() and render then in an iframe or separate window using a Blob URL, to avoid location.href, though that will work, too.