So I need to open tabs from my website to other websites using JavaScript and jQuery (I cannot use an <a> tag as a requirement). The links come from the database, so I set the title of the object the user clicks to the link and then redirect them when they click it, and I have code that does this alright:
<script language="javascript" type="text/javascript">
var RedirectCount = 0;
$(document).ready(function () {
$(".ResultRow").click(function () {
if ($(this).attr("title") != "")
{
window.open($(this).attr("title"), "Program" + RedirectCount, "");
RedirectCount = RedirectCount + 1;
}
});
});
</script>
So this works great, except that many of the URL’s have # signs in them which is supposed to open up a specific tab on the destination page. This works on Firefox, but IE 8 removes the # tag before the second tab opens. I also tried recoding the URL using JavaScript’s built in URLEncode function, ASP.NET’s URLEncode function, and simply replacing # signs with %20, none perform the correct action.
I do not have access to other browsers, and I’ve been googling the problem for the last half hour without finding an answer, so what I’m looking for are the answers to these two questions:
-
Is there any other way to open a new tab that will always work with a
#besides window.open or an<a target="_blank">tag? -
How many browsers don’t perform this action correctly (especially Google Chrome)? Has the issue been fixed in IE9+?
The solution is that Visual Studio interferes with the way in which IE8 runs the JavaScript code, and that the code listed in the question will in fact work properly when running under normal conditions. I do not know why, nor do I feel that it is important enough to figure out why, perhaps in a few years someone may find this answer out and add it to the comments below.