How can I get window.location to work...?

Bruce Gust
Bruce Gust used Ask the Experts™
on
Here's my code:

	$('#wellness_button').click(function(event) {
		//alert("Yo");
		var portal = $('#the_link').val();
		var bdg = $('#initials').val();
		var dbox = $('#decline');
		if(bdg=="") {
			alert("Don't forget to initialize the form.");
		}
		else {
			if(dbox.is(':checked')) {
				alert("wrong");
			}
			else {
				//console.log(portal);
				window.location=portal;
			}
		}
	});

Open in new window


Everything is working great except for when my user gets to the last "else" clause and I want to redirect them to the url that's housed in the "portal" variable.

Instead of getting "https://the_new_link.com," it appends that link to the existing url so it comes out "https://my_current_page.net/%7Bhttps://the_new_link.com."

What am I missing?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
replace :
window.location=portal;
by :
window.location.href = portal;
or by :
location.href = portal;

https://developer.mozilla.org/en-US/docs/Web/API/Location
Bruce GustPHP Developer

Author

Commented:
Hey, Leak!

I figured it out!

The URL that I was passing in as the "portal" value had a curly brace at the front and back end. I took a closer look at the bogus URL and noticed "%7B." I looked that up, recognized the character, adjusted the code and BOOM!

The sun is shining once again!

Thanks as always for weighing in!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial