Addition to JavaScript to open results in new window

JavaScript code text file is attached.

Right now when clicked, or hit entered the results display on the same window. Would like the results to open in new window or tab.

Thanks!
JSCode.txt
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.

Dorababu MSenior Software EngineerCommented:
Have you tried
window.open("http://query.nytimes.com/search/query?query=" + document.search_form.search.value + "&date_select=full");

Open in new window

1

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
Anthony PangilinanDeveloperCommented:
You might also need to pass "_blank" to Dorababu M's solution.

Edit: Nope, "_blank" is the default already. (https://www.w3schools.com/jsref/met_win_open.asp)
0
Slick812Commented:
greetings Member_2_7971128, , , If you add an <iframe> to your page then the user can see the New York Times search page on the same page as the search input

the code below may work for you -
<!DOCTYPE html>
<html><head><title>NYT SEARCH</title>
<script>
function searchthis (keypressed)
{
	var keynum

	if(window.event) // IE
		keynum = keypressed.keyCode;
	else if(keypressed.which) // Netscape/Firefox/Opera
		keynum = keypressed.which;

	if (keynum == 13){
		//alert(keynum + " key code");
		if (document.search_form.search.value.length > 2) {
        document.getElementById("iframe1").src = "http://query.nytimes.com/search/query?query=" + encodeURIComponent(document.search_form.search.value) + "&date_select=full";
		}
	else{
		alert( "Please enter the search term longer than 2." );
		document.search_form.search.focus();
		event.returnValue=false;
		}
		event.returnValue=false;
	}
}

function clickthis ()
{
	if (document.search_form.search.value.length > 2) 
		{
		document.getElementById("iframe1").src = "http://query.nytimes.com/search/query?query=" + encodeURIComponent(document.search_form.search.value) + "&date_select=full";
		}
	else
		{
		alert( "Please enter the search term longer than 2." );
		document.search_form.search.focus();
		event.returnValue=false;
		}
		event.returnValue=false;
}
</script>

</head>
<body>
<p>
<form name="search_form" id="search_form" target="_blank">
		<label for="s" style="color:CE0505;font-weight:bold;">Search the New York Times:&nbsp;</label>
		<input  type="text" name="search" id="search" size="15" value="" style="font-size: 12px;" onKeyPress="searchthis(event);">
		<INPUT   TYPE="button" NAME="SButton" VALUE="Go" style="height: 20px; vertical-align: center; font-size: 12px;" onClick="clickthis();"> 
</form>
</p>
<iframe id="iframe1" src="" style="width:99%;height:483px;">
<p>Your browser does not support iframes.</p>
</iframe>


</body>
</html>

Open in new window


I added the  encodeURIComponent( ) to make sure the input text was correct for a "URL" string, which does not allow certain characters
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Member_2_7971128Author Commented:
Yes I tried window.open, didn't work.

Sorry can not use iframe, that is not a requirement. Will have to find another way.

Thanks.
0
Anthony PangilinanDeveloperCommented:
Is there default behavior on your click element that needs preventDefault() called?
0
Slick812Commented:
This question has been inactive fo more than 14 days, and will be closed for clean up, Points split for experts comments as a possible solution.
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
JavaScript

From novice to tech pro — start learning today.