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.
Simply use window.location="http://www.newlocation.com". See the example below:
<head>
<script type="text/javascript">
<!--
function Redirect()
{
window.location="http://www.newlocation.com";
}
document.write("You will be redirected to main page in 10 sec.");
setTimeout('Redirect()', 10000);
//-->
</script>
</head>
You can use Meta tag for client side redirection.
<META http-equiv="refresh" content="5;URL=http://www.example.com">
Which will redirect the user to http://www.example.com after 5 seconds.
window.location
is a property of window object.
You can try function version too
function myCustomHref() { window.open ('http://www.newlocation.com', '_self'); }
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.com")
}
</script>
For full details you can view the following website,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.