0

I'm looking for the solution : opening the Popup window by inserting a value for example.

if your site is: www.example.com/ by inserting a value as a text let's take ' results ' and clicking on the button show us this Popup page: www.example.com/results

actually I'm using this Code, but that shows the result in the same page

<!DOCTYPE html> 
<html> 
<head> 
	<title>Redirect url in Javascript</title> 
</head> 
<body> 
<input id = "url" type = "text" name = "url"
						placeholder = "Enter a url here"> 
<input type = "submit" name = "button" onclick = "fun()"> 
<script> 
function fun() { 
	var url= document.getElementById("url").value; 
	document.write("Redirecting to the url in 3 seconds..."); 
	setTimeout(function(){window.location = url;}, 3000); 
} 




</script> 
</body> 
</html> 

4
  • You want to redirect to www.example.com/results on button click. Commented Apr 12, 2020 at 20:03
  • What kind of pop-up window are you particularly looking for? Is the browser supposed to (a) open a new tab? Or (b) a true modal(?) pop-up window? Or (c) a HTML overlay that's supposed to look like a pop-up window? Commented Apr 12, 2020 at 20:03
  • I'm want to open the url as a overly or pop-up window Commented Apr 12, 2020 at 20:04
  • Yes after input results and clicking on the button to redirect to www.example.com/results but it should open in pop-up, not in the same window cse_vikashgupta Commented Apr 12, 2020 at 20:06

3 Answers 3

1

You will need to window.open(url) with an extra parameter like below.

function fun() { 
    var url= document.getElementById("url").value; 
    document.write("Redirecting to the url in 3 seconds..."); 
    var currentUrl = window.location.url;
    setTimeout(function(){    window.open(currentUrl+"/"+url, '_blank', 'location=yes,height=500,width=1000,scrollbars=yes,status=yes')}, 3000); 
} 

Third Param describe how your new window would look like.(For ex. it's height and width) For more info Read Article

Search for Window features in Article.

Sign up to request clarification or add additional context in comments.

Comments

0

you should use window.open(url) and you can use `` or "" with + to create the url that you want

3 Comments

I tried it but that doesn't show the pop-up in a new window
although it worked for me but if you add _blank as a second parameter it will open in a new tab
setTimeout(function(){window.open("https://" + url,"_blank");}, 3000); }
0

two issues with your code:

1) you need to include https:// in the url 2) on js fiddle and stackoverflow you can only test their domain

so if you enter www.stackoverflow.com you'll see that the code below works as intended

<!DOCTYPE html> 
<html> 
<head> 
	<title>Redirect url in Javascript</title> 
</head> 
<body> 
<input id = "url" type = "text" name = "url"
						placeholder = "Enter a url here"> 
<input type = "submit" name = "button" onclick = "fun()"> 
<script> 
function fun() { 
	var url= document.getElementById("url").value; 
	document.write("Redirecting to the url in 3 seconds..."); 
	setTimeout(function(){window.location = "https://" + url;}, 3000); 
} 




</script> 
</body> 
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.