React Js change url based on dropdown selected value| Change URL on select
React Js change url based on dropdown selected value| Change URL on select:In Reactjs, to open a selected option in a new tab, you can use the "window.open()" method with the "_blank" target attribute. This triggers a new browser window displaying the selected content in a separate tab, without replacing the current page. It's a convenient way to present additional information or resources to the user without disrupting their current browsing experience




Thanks for your feedback!
Your contributions will help us to improve service.
How can I use Reactjs to dynamically change the URL based on the selected value in a dropdown?
This React JS code creates a dropdown with three options: "Font Awesome Icons," "Tutorials Plane," and "Sarkari Naukri Exams." When the user selects an option, the handleDropdownChange
function is triggered, and the corresponding URL is opened in a new tab. The code uses the window.open
method to achieve this behavior. The parent component, App
, renders the dropdown and displays a title.
React Js change url based on dropdown selected value
xxxxxxxxxx
<script type="text/babel">
const { useState } = React;
// Child Component
const Dropdown = () => {
const handleDropdownChange = (e) => {
const selectedValue = e.target.value;
window.open(selectedValue, '_blank'); // Open the selected URL in a new tab
};
return (
<div>
<h2>Select a value:</h2>
<select onChange={handleDropdownChange}>
<option value="https://fontawesomeicons.com">Font Awesome Icons </option>
<option value="https://tutorialsplane.com">Tutorials Plane </option>
<option value="https://sarkarinaukriexams.com">Sarkari Naukri Exams </option>
</select>
</div>
);
};
// Parent Component
const App = () => {
return (
<div className='container'>
<h1>React URL Based on Dropdown</h1>
<Dropdown />
</div>
);
}
ReactDOM.render(<App />, document.getElementById('app'));
</script>