簡體   English   中英

Javascript菜單-如何將鏈接重定向到另一個網頁

[英]Javascript Menu - How to redirect link to another webpage

我熟悉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>");
}

我試圖將“ whatsnew”頁面重定向到我的客戶博客... https://ashleyvictoriaproductions.wordpress.com/

我該怎么做呢?

試試這個?

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

將課程添加到您的鏈接

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/";
});

在純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>");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM