How to Create a New Window with a Specific Link Using jQuery?

Estimated read time 2 min read

To create a new window with a specific link using jQuery, you can use the window.open() method. Here’s an example:

<button id="open-link">Open Link</button>

<script>
	$(document).ready(function(){
		$("#open-link").click(function(){
			window.open("https://www.example.com");
		});
	});
</script>

In this example, we have a button element with the ID “open-link”. We use jQuery to listen for clicks on the button, and when the button is clicked, we use the window.open() method to create a new window with the URL “https://www.example.com“.

You can also add additional options to the window.open() method to customize the new window’s appearance and behavior. Here’s an example that opens the link in a new window with a specific size and position:

<button id="open-link">Open Link</button>

<script>
	$(document).ready(function(){
		$("#open-link").click(function(){
			window.open("https://www.example.com", "_blank", "width=800,height=600,top=100,left=100");
		});
	});
</script>

In this example, we add three additional parameters to the window.open() method. The second parameter ("_blank") specifies that the link should be opened in a new window. The third parameter ("width=800,height=600,top=100,left=100") specifies the size and position of the new window.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply