JavaScript redirection with hash / pound / #

Therefore, I need to open tabs from my site to other sites using JavaScript and jQuery (I cannot use the <a> tag as a requirement). The links are taken from the database, so I set the title of the object that the user clicks on the link and then redirects them when they click on it, and I have code that does this in order:

 <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> 

That way, this works great, except that many URLs have # signs that should open a specific tab on the landing page. This works in Firefox, but IE 8 removes the # tag before opening the second tab. I also tried recoding the URL using the JavaScript built into the URLEncode function, the ASP.NET URLEncode function, and simply replacing the # signs with %20 , none of them did the right thing.

I don’t have access to other browsers, and I searched for the problem in the last half hour without finding an answer, so I'm looking for answers to these two questions:

  • Is there any other way to open a new tab that will always work with # besides window.open or the <a target="_blank"> tag?

  • How many browsers do not perform this action correctly (especially Google Chrome)? Is the problem fixed in IE9 +?

+4
source share
1 answer

The solution is that Visual Studio interferes with the way IE8 runs JavaScript code, and that the code provided in the question does work correctly under normal conditions. I don’t know why and don’t feel that it’s important enough to find out why, maybe in a few years someone can find this answer and add it to the comments below.

+1
source

Source: https://habr.com/ru/post/1385370/


All Articles