I am pretty much new to programming and just getting my hands dirty. I am trying to show something to the user depending upon the length of the URL. Following is the code
<!DOCTYPE HTML>
<html>
<head>
<title>Random</title>
<meta charset="utf-8" />
</head>
<body id="main" style="display:none">
<h1>
Paste something
</h1>
<form action="abcd.php" method="post">
<input type="text" name="URL" placeholder="random url" id="something" required>
<input type="submit" value="do something">
</form>
</body>
<script>
if (window.location.href.length - 1 > 35) {
alert("redirect");
} else {
alert("show");
}
</script>
</html>
In my case, the minimum length of the URL is 35 characters. However, when I add the URL that long for the first time the "redirect" alert shows up instead of showing the "show" alert. It runs fine the second time. And after I delete the cache, the whole story repeats.
PS: query string variable I get added on its own. For example, when I hit domain.com its written domain.com/?i=1
in the address bar on its own(Only when I hit the URL for the first time after deleting cache).
How can I make it work in the first go? Any help appreciated.