0

I want to record all links inputted by a user, then when they press a button, open each link in a separate tab. My current code is:

<html>
<head>
    <script type='text/javascript'>
    function clickyClick() {
        url = document.getElementById("serieslink").value
        window.open(url, '_blank');
    }
</script>
</head>
<body>
  <form>Series Name:
    <input type="text" name="series1name" id="seriesname"><br>
Series Link:
    <input type="text" name="series1link" id="serieslink">
  </form>
  <br>
  <button onclick="AddSeries()">Add A New Series</button><br>
  <button onclick="clickyClick()">Open Incomplete Series</button>

</body>

As it is, my code will take a user inputed link and a name and bring them to that single link. I would like for them to be able to enter multiple links, which are then saved, then click a button and be brought to all pages.

Warstolrem
  • 131
  • 1
  • 12
  • Multiple input elements with a common class, then `getElementsByClassName()` to get a list of those elements, then a loop to process each value? – nnnnnn Aug 23 '16 at 22:00

1 Answers1

1

There could be various ways by which you can take multiple links as input in the text.

One of the ways is comma separated. In that Case -

function clickyClick() {
    var urls = document.getElementById("serieslink").value.split(",");
    for(url in urls){
            window.open(url, '_blank');
    }
}

If you want to maintain a Javascript array for storing URLs,

var urlArray = [];
urlArray.push(url);

However, you will also have to handle the case of retaining its value when the page refreshes. For that, you will need to use localStorage to store and retrieve.

Refer to this post to know how.

Community
  • 1
  • 1
Harshul Pandav
  • 1,016
  • 11
  • 23
  • I don't necessarily want to enter all the links at the same time. The purpose of this script is to add tv shows that I'm watching and links to those shows, so if I start two series at different times I want to be able to add them as I watch them. Any advice? – Warstolrem Aug 23 '16 at 22:27
  • In your original question you wanted to "click a button and be brought to all pages". However, by your comment above I understand you want to store the links with AddSeries(). Is that correct? – Harshul Pandav Aug 23 '16 at 22:34
  • That is correct, I'm sorry I wasn't more clear I want to do both. I want to use AddSeries() to add a link to a database of some sort, which can all be recalled at the same time using clickyClick. I believe your "for(url in urls){" will work for that, but I want to know how to make a class or array of some sort that can store all links I add – Warstolrem Aug 23 '16 at 22:45