Javascript菜单 - 如何将链接重定向到其他网页

时间:2015-05-15 16:27:55

标签: javascript css

我熟悉html / css导航编码。但我似乎无法在我的客户菜单导航中获取其中一个链接以重定向到她的博客。我知道在HTML中你可以使用target =" _blank"。但我似乎无法想象如何在javascript中重定向。

这是菜单上的html:

<div id="menu">
    <script>setMenuOption('home');</script>
</div>

这是javascript:

function setMenuOption(pageID) {

    if (pageID == 'home') {
        reset();
        return;
    }

    if (pageID == 'about') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a class='active'>ABOUT AVP</a>");
        document.write("<a href='services.html'>SERVICES</a>");
        document.write("<a href='affiliates.html'>AFFILIATES</a>");
        document.write("<a href='gallery.html'>GALLERY</a>");
        document.write("<like href='whatsnew.html'>WHAT'S NEW</a>");
        document.write("<a href='contact.html'>CONTACT</a>");
    }

    if (pageID == 'services') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a href='about.html'>ABOUT AVP</a>");
        document.write("<a class='active'>SERVICES</a>");
        document.write("<a href='affiliates.html'>AFFILIATES</a>");
        document.write("<a href='gallery.html'>GALLERY</a>");
        document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");
        document.write("<a href='contact.html'>CONTACT</a>");
    }


    if (pageID == 'affiliates') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a href='about.html'>ABOUT AVP</a>");
        document.write("<a href='services.html'>SERVICES</a>");
        document.write("<a class='active'>AFFILIATES</a>");
        document.write("<a href='gallery.html'>GALLERY</a>");
        document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");
        document.write("<a href='contact.html'>CONTACT</a>");
    }

    if (pageID == 'gallery') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a href='about.html'>ABOUT AVP</a>");
        document.write("<a href='services.html'>SERVICES</a>");
        document.write("<a href='affiliates.html'>AFFILIATES</a>");
        document.write("<a class='active'>GALLERY</a>");
        document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");
        document.write("<a href='contact.html'>CONTACT</a>");
    }

    if (pageID == 'whatsnew') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a href='about.html'>ABOUT AVP</a>");
        document.write("<a href='services.html'>SERVICES</a>");
        document.write("<a href='affiliates.html'>AFFILIATES</a>");
        document.write("<a href='gallery.html'>GALLERY</a>");
        document.write("<a class='active'>WHAT'S NEW</a>");
        document.write("<a href='contact.html'>CONTACT</a>");
    }

    if (pageID == 'contact') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a href='about.html'>ABOUT AVP</a>");
        document.write("<a href='services.html'>SERVICES</a>");
        document.write("<a href='affiliates.html'>AFFILIATES</a>");
        document.write("<a href='gallery.html'>GALLERY</a>");
        document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");
        document.write("<a class='active'>CONTACT</a>");
    }

    if (pageID == 'footer') {
        document.write("<a href='index.html'>HOME</a>");
        document.write("<a href='about.html'>ABOUT AVP</a>");
        document.write("<a href='services.html'>SERVICES</a>");
        document.write("<a href='affiliates.html'>AFFILIATES</a>");
        document.write("<a href='gallery.html'>GALLERY</a>");
        document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");
        document.write("<a href='contact.html'>CONTACT</a>");
    }
}

function reset() {

    document.write("<a href='about.html'>ABOUT AVP</a>");
    document.write("<a href='services.html'>SERVICES</a>");
    document.write("<a href='affiliates.html'>AFFILIATES</a>");
    document.write("<a href='gallery.html'>GALLERY</a>");
    document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");
    document.write("<a href='contact.html'>CONTACT</a>");
}

我正在尝试重定向&#34; whatsnew&#34;页面到我的客户博客... https://ashleyvictoriaproductions.wordpress.com/

我该怎么做呢?

3 个答案:

答案 0 :(得分:0)

尝试过这个吗?

document.write("<a href='https://ashleyvictoriaproductions.wordpress.com/' target='_blank'>WHAT'S NEW</a>");

答案 1 :(得分:0)

在您的链接中添加课程

document.write("<a class='whatsNew' href='whatsnew.html'>WHAT'S NEW</a>");

然后是jQuery

$('.whatsNew').on('click',function(e){
   e.preventDefault();
   window.location.href = "https://ashleyvictoriaproductions.wordpress.com/";
});

答案 2 :(得分:0)

用于在纯JS中重定向:

window.location.href = "https://ashleyvictoriaproductions.wordpress.com/"

如果我理解你的问题,你只需要替换相关链接“whatsnew.html”:

document.write("<a href='whatsnew.html'>WHAT'S NEW</a>");

使用博客网址:

document.write("<a href='https://ashleyvictoriaproductions.wordpress.com/' target='_blank'>WHAT'S NEW</a>");