Search code examples
javascripttumblr

Pulling javascript from tumblr with specified username


I am trying to get a fairly simple bit of code to work. The essence of it is just to take user input, append it on to a source URL, and then use a script to display the appropriate tumblr feed.

I have spent some time on this, and I can't get my head around how javascript works enough to do something like this.

This is what I have so far:

<html>
<body>
    <form>
        Tumblr Username:<br>
        <input type="text" name="username">
        <br>
        <br>
        <input type="submit" value="Submit">
    </form>
    <script type="text/javascript" src= username + ".tumblr.com/js"></script>
</body>
</html>

Thanks in advance.


Solution

  • Because the JS file that is on username.tumblr.com uses document.write, I think it'd be better to just load the actual url of the user in an iframe, as this wouldn't require you to refresh the page, while creating a mini page inside your page.

    This won't work on the snippet tool here or on JSFiddle, but I've tested it on a web server:

    <html>
    
    <body>
      <script>
        function getUN() {
          var username = document.getElementsByName("username")[0].value;
          document.getElementById("tumblrframe").src = "http://" + username + ".tumblr.com";
    
        }
      </script>
    
      Tumblr Username:
      <br>
      <input type="text" name="username">
      <br>
      <br>
      <button onclick="getUN()">Submit</button>
      <br/>
      <br/>
      <iframe id="tumblrframe" width="80%" height="600px"></iframe>
    
    </body>
    
    </html>