最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How redirect to other page using HTML or JavaScript - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

4 Answers 4

Reset to default 5

Simply 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

发布评论

评论列表(0)

  1. 暂无评论