J Fav
J Fav

Reputation: 3

How can I target multiple URLs, using a single form and keyword?

I am trying to create something (basically a search engine, more or less), where I can enter a keyword into the search box, and that keyword will be implemented into several predefined URLs, and open multiple tabs with the search term for the respective pages. I know this is somewhat basic, but for the life of me, I can't pull my thoughts together to make it happen.

Example:

Search for: PHUN

The following links would be modified and open new tabs/pages with the search term.

https://dilutiontracker.com/app/search/PHUN
https://flash-sec.com/companysearch/?ticker=PHUN
https://www.sec.gov/edgar/search/#/entityName=PHUN

Ideally, I would like to build a custom search engine where I could just add it to my browser and execute this straight from the search bar. Alternatively, I could use a simple HTML (or similar) page.

=========================================================

This is ultimately what I ended up using, the only downside is that the pop-up blocker prevents the tabs opening after the first link on the first attempt, but they open as soon as you allow them (at least in Firefox).

<input type="text" id="text" /> 
<input type="button" value="Submit" id="btn" onclick="javascriptFun()" />

<script>
function javascriptFun(){
window.open('https://dilutiontracker.com/app/search/' + document.getElementById('text').value,'_blank');
window.open('https://flash-sec.com/companysearch/?ticker=' + document.getElementById('text').value,'_blank');
window.open('https://www.sec.gov/edgar/search/#/entityName=' + document.getElementById('text').value,'_blank');

}

// (Could not press enter to submit) Listen for Enter key press on the input field
document.getElementById('text').addEventListener('keypress', function(event) {
    if (event.key === 'Enter') {
        event.preventDefault(); // Prevent the default action to stop submitting the form
        javascriptFun(); // Call the function to open the websites
    }
});

</script>

=========================================================

I found this post describing how to accomplish this using a web page/form:

Input text in form-field, generate multiple URLs on submit and open the links in new tabs

This will work for now. My goal is to create a search engine shortcut for web browsers that will execute this automatically from the address bar, but if anyone has a link or some code to get there quicker, let me know.

Upvotes: 0

Views: 281

Answers (0)

Related Questions