admin管理员组文章数量:1024678
Im begginer in WebProgramming so maybe my questuion will seem naive to some of you. I want to run a simple JavaScript function without any click to implement a redirection.
I try this:
@inherits System.Web.WebPages.WebPage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
</head>
<body>
<a href="/OauthCallBack/GmailOAuthCallback"></a>
</body>
</html>
But it dosen't work.
Any idea wat I am missing?
Thank you in advance.
Im begginer in WebProgramming so maybe my questuion will seem naive to some of you. I want to run a simple JavaScript function without any click to implement a redirection.
I try this:
@inherits System.Web.WebPages.WebPage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
</head>
<body>
<a href="/OauthCallBack/GmailOAuthCallback"></a>
</body>
</html>
But it dosen't work.
Any idea wat I am missing?
Thank you in advance.
Share Improve this question asked Aug 11, 2014 at 8:04 MichaelMichael 13.6k59 gold badges170 silver badges315 bronze badges 4- You haven't got any JavaScript in the code you've shared. (But if you want to do a redirect, then do it with an HTTP Location header, not with JavaScript). – Quentin Commented Aug 11, 2014 at 8:07
-
Your title states "HTML or Javascript" but your question only only mentions javascript. If you're happy with HTML, then look at META redirection
<meta http-equiv="refresh" content="0;URL='http://www.example./'" />
– freefaller Commented Aug 11, 2014 at 8:08 - Your probobly missing the text for your <a> link (^_^) – Stuart Commented Aug 11, 2014 at 8:11
- You must write some text between anchor open tag<a> and close tag </a>, – Aditya Commented Aug 11, 2014 at 8:38
4 Answers
Reset to default 5Simply use window.location="http://www.newlocation.". See the example below:
<head>
<script type="text/javascript">
<!--
function Redirect()
{
window.location="http://www.newlocation.";
}
document.write("You will be redirected to main page in 10 sec.");
setTimeout('Redirect()', 10000);
//-->
</script>
</head>
More info here
You can use Meta tag for client side redirection.
<META http-equiv="refresh" content="5;URL=http://www.example.">
Which will redirect the user to http://www.example. after 5 seconds.
window.location
is a property of window object.
You can try function version too
function myCustomHref() {
window.open ('http://www.newlocation.', '_self');
}
Here you can find more optional properties
if you want to redirect from a webpage to another using javascript,then you can try the following script,
<script>
function newPage() {
window.location.assign("http://www.w3schools.")
}
</script>
For full details you can view the following website,
http://www.w3schools./js/js_window_location.asp
Im begginer in WebProgramming so maybe my questuion will seem naive to some of you. I want to run a simple JavaScript function without any click to implement a redirection.
I try this:
@inherits System.Web.WebPages.WebPage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
</head>
<body>
<a href="/OauthCallBack/GmailOAuthCallback"></a>
</body>
</html>
But it dosen't work.
Any idea wat I am missing?
Thank you in advance.
Im begginer in WebProgramming so maybe my questuion will seem naive to some of you. I want to run a simple JavaScript function without any click to implement a redirection.
I try this:
@inherits System.Web.WebPages.WebPage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
</head>
<body>
<a href="/OauthCallBack/GmailOAuthCallback"></a>
</body>
</html>
But it dosen't work.
Any idea wat I am missing?
Thank you in advance.
Share Improve this question asked Aug 11, 2014 at 8:04 MichaelMichael 13.6k59 gold badges170 silver badges315 bronze badges 4- You haven't got any JavaScript in the code you've shared. (But if you want to do a redirect, then do it with an HTTP Location header, not with JavaScript). – Quentin Commented Aug 11, 2014 at 8:07
-
Your title states "HTML or Javascript" but your question only only mentions javascript. If you're happy with HTML, then look at META redirection
<meta http-equiv="refresh" content="0;URL='http://www.example./'" />
– freefaller Commented Aug 11, 2014 at 8:08 - Your probobly missing the text for your <a> link (^_^) – Stuart Commented Aug 11, 2014 at 8:11
- You must write some text between anchor open tag<a> and close tag </a>, – Aditya Commented Aug 11, 2014 at 8:38
4 Answers
Reset to default 5Simply use window.location="http://www.newlocation.". See the example below:
<head>
<script type="text/javascript">
<!--
function Redirect()
{
window.location="http://www.newlocation.";
}
document.write("You will be redirected to main page in 10 sec.");
setTimeout('Redirect()', 10000);
//-->
</script>
</head>
More info here
You can use Meta tag for client side redirection.
<META http-equiv="refresh" content="5;URL=http://www.example.">
Which will redirect the user to http://www.example. after 5 seconds.
window.location
is a property of window object.
You can try function version too
function myCustomHref() {
window.open ('http://www.newlocation.', '_self');
}
Here you can find more optional properties
if you want to redirect from a webpage to another using javascript,then you can try the following script,
<script>
function newPage() {
window.location.assign("http://www.w3schools.")
}
</script>
For full details you can view the following website,
http://www.w3schools./js/js_window_location.asp
本文标签: How redirect to other page using HTML or JavaScriptStack Overflow
版权声明:本文标题:How redirect to other page using HTML or JavaScript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745610895a2158997.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论