JS to open serach results in a new tab/window.

I have a JS Code which goes to a new site upon click or/and enter. I would like to the new site to open in a new tab or window. Right now it is opening in the same window. I have tried adding window.open(" ") around my links, but that didn't work. Also use of iframes is not allowed. Your help is greatly appreciated.
Member_2_7971128Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OMC2000Commented:
Could you post an example of your window.open() statement. It works in general. Probably your browser doesn't allow popup windows?
0
Member_2_7971128Author Commented:
Hum may be I did it wrong. This is what I tried.
document.location = window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");
0
OMC2000Commented:
document.location is a string containing URL

 window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");
returns window object.

So, statement
document.location = window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");
is not correct

However, window.open should work before and window should appear. What do you mean does not work? You don't see new window or it appears and does not contain expected result?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Member_2_7971128Author Commented:
It opens a new window with results, but on the current window, it also give a error saying "HTTP Error 404.0 - Not Found

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

how should I fix this? Thanks.
0
OMC2000Commented:
Well, command

 window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");

opens a new windows and fills it with result, it returns windows object. You assign it to current page location property and it reloads current page with result of window object conversion to string. It is not URL, and that's why you are getting 404 error.

just leave statement
 window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");

instead of

document.location = window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");
0
Member_2_7971128Author Commented:
Thanks! It works. On click is now perfect. On enter however is now opening an extra window with my home page. Any tips? Thanks.
0
OMC2000Commented:
Then I need more details. Post HTML code, where you embedded this JS statement.
0
Member_2_7971128Author Commented:
Sure, see attached.
FullCode.txt
0
OMC2000Commented:
remove  'target="_blank"' from the form description. This is the reason of the last problem. Form is getting submitted.

And, I guess, you should replace in searchthis ()

document.location = "http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full";

with

window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");
0
Member_2_7971128Author Commented:
ok, I made those changes, but still same behavior on IE and Firefox. Chrome Ok.
0
OMC2000Commented:
Add

 onsubmit="return false"

to form definition:

      <form name="search_form" id="search_form" onsubmit="return false">

form is getting submitted on Enter into the save window in parallel with new window openning
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Member_2_7971128Author Commented:
That did it! Thanks for all the help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.