0

I found this solution here Form value creates a url to make text input form a URL on submit.

Is it possible to add rel="nofollow noopener noreferrer" and target="_blank" to the the URL?

thanks

<script>
function process()
{
var url="http://name.com/" + document.getElementById("url").value;
location.href=url;
return false;
}
</script>
<form onSubmit="return process();">
URL: <input type="text" name="url" id="url"> <input type="submit" value="go">
</form>
  • Not if you set `location.href`. Either modify the `action` and set form `target` or use `window.open()` – charlietfl Nov 13 '17 at 04:32
  • Wow this is so unbelievably insecure! But ignoring that, you can emulate _blank by calling `window.open(url)` instead of setting location. The `rel` attributes would be totally meaningless because crawlers cannot see your user-generated link. – skylize Nov 13 '17 at 04:36

1 Answers1

0

There are two approaches to get the submission response page/action page to open in a new window:

  1. change your location.href call to a window.open call; refer to https://developer.mozilla.org/en-US/docs/Web/API/Window/open for documentation on using window.open

OR...

  1. instead of loading the url in your javascript, set the form action attribute in the tag and also set a target of _blank in the same tag. Use your javascript function to return true to submit the form to the action url or return false to prevent submission.

Then, too set a nofollow behavior for the new page that the form action directs too, you can either disallow its indexing in robots.txt or add a metatag, as noted in the answer here: https://webmasters.stackexchange.com/questions/13837/nofollow-in-a-form-action

Anson W Han
  • 409
  • 2
  • 7