Redirecting to another page without loading the current page in jquery

I want to redirect to another page from 1 page without showing the contents of this page using javascript / jquery.

So, for example, I would either type or come from a search engine to a page on my site, say www.mysite.com/aaa/, and I need to redirect to www.mysite.com/bbb/without showing the content www.mysite.com/aaa/.

The server side is asp.net, and I can do it with Response.Redirect, but I don't want to change the code.

From my limited knowledge, I cannot use document.readyor window.load, since both will load the contents of the page in the browser before being redirected.

I do not know about any other thing that would help me with this. I tried a hard search, but could not get anything useful.

I have something here . I can get this in the header, but right at the top of the header may not be possible. Plus the answer does not look very convincing. However, you can try and update this question with conclusions.

Please, help!

Thanks in advance!

+4
source share
1 answer

When the web browser engine reads an HTML document and identifies the element script, it immediately calls the JavaScript interpreter and executes the code. So, if your document starts with JavaScript that redirects from the page, the client should not show the remaining document. Something like this might work:

<!DOCTYPE html>
<html>
  <head> 
    <script type='text/javascript'>
        //using "replace" removes the current page from browser history
        location.replace('page_b.html');
    </script>

, -, - CSS,

<style type='text/css'>
   body {display:none}
</style>
+5

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


All Articles