简体   繁体   中英

How redirect to other page using HTML or JavaScript

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>

More info here

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'); }

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.com")
}
</script>

For full details you can view the following website,

http://www.w3schools.com/js/js_window_location.asp

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM