问题描述
我想从1页重定向到另一个页面而不使用javascript / jquery显示该页面的内容。
I want to redirect to another page from 1 page without showing contents of that page using javascript/jquery.
所以例如我要么输入要么来自我网站上一个页面的搜索引擎说 www.mysite.com/aaa /
我应该被重定向到 www.mysite.com/bbb /
没有显示 www.mysite.com/aaa /
的内容。
So for example I would be either typing or coming from a search engine to a page on my website say www.mysite.com/aaa/
and I should get redirected to www.mysite.com/bbb/
without showing the contents of www.mysite.com/aaa/
.
服务器端是asp.net,我可以使用 Response.Redirect
执行此操作,但我不想更改代码。
The server side is asp.net and I can do this using Response.Redirect
but I do not want a code change.
根据我的有限知识,我不能使用 document.ready
或 window.load
因为两者都会加载内容重定向前浏览器中的页面。
From my limited knowledge, I cannot use document.ready
or window.load
as both will load the contents of the page in the browser before redirecting.
我不知道有任何其他可以帮助我实现这一目标的事情。尝试过努力搜索但无法获得任何有用的东西。
I am not aware of any other thing which would help me achieve this. Tried hard searching but could not get anything useful.
我得到的东西。我可以在标题中有这个,但在标题的顶部可能是不可能的。而且答案看起来并不十分令人信服。但是,可以尝试一下并用调查结果更新这个问题。
I got something here. I can have this in the header but right at the top of the header might not be possible. Plus the answer is not looking very convincing. However, can try it out and update this question with the findings.
请帮助!
提前致谢!
推荐答案
当Web浏览器引擎读取HTML文档并标识脚本$ c时$ c>元素,它立即调用JavaScript解释器并执行代码。因此,如果您的文档以重定向远离页面的JavaScript开头,则不应向客户端显示剩余文档。这样的事情可以起作用:
When the the web browser engine reads an HTML document and identifies a script
element, it immediately invokes the JavaScript interpretator and executes the code. So, if your document starts with a JavaScript which redirects away from the page, the client shouldn't be shown the remaining document. Something like this could 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,例如
Also, if there is something on the current page that should not be displayed to the client while the redirect is in process - you can inject some additional CSS, like
<style type='text/css'>
body {display:none}
</style>
这篇关于重定向到另一个页面而不在jquery中加载当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!