简体   繁体   English

Javascript菜单-如何将链接重定向到另一个网页

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

I am familiar with html/css navigation coding. 我熟悉html / css导航编码。 But I can't seem to get one of the links in my clients menu navigation to redirect to her blog. 但是我似乎无法在客户菜单导航中找到链接之一来重定向到她的博客。 I know in html you can use target="_blank". 我知道在html中可以使用target =“ _ blank”。 But I can't seem to figure how to redirect in javascript. 但我似乎无法弄清楚如何在javascript中重定向。

This is the html I have for the menu: 这是我在菜单中使用的html:

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

This is the javascript: 这是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>");
}

I am trying to redirect the "whatsnew" page to my clients blog... https://ashleyvictoriaproductions.wordpress.com/ . 我试图将“ whatsnew”页面重定向到我的客户博客... https://ashleyvictoriaproductions.wordpress.com/

How can I go about doing this? 我该怎么做呢?

试试这个?

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

Add class to your link 将课程添加到您的链接

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

And then jQuery 然后jQuery

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

For redirecting in plain JS: 在纯JS中重定向:

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

If i understand your question correctly though, you just need to replace the relative link "whatsnew.html" in: 如果我正确理解了您的问题,则只需在以下位置替换相对链接“ whatsnew.html”:

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

with the blog url: 使用博客网址:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加指向可点击 HTML 图像的链接,该链接将使用 JAVASCRIPT 重定向到另一个网页 - Adding link to a clickable HTML image with a link that will redirect to another webpage using JAVASCRIPT 如何在wordpress网站中使用javascript重定向到另一个链接? - How to redirect to another link with javascript in a wordpress site? 如何通过随机数将网页重定向到另一个网页? - How to redirect a webpage to another webpage by random number? 单击菜单时,超链接问题不会重定向到另一个网页 - hyperlink issue dont redirect to another webpage when click on the menu 如何将网页从一个域重定向到另一个域? - How to redirect webpage from one domain to another? 如何重定向到另一个网页? - How do I redirect to another webpage? 如何使用Javascript或jQuery重定向网页? JavaScript重定向 - How do I redirect my webpage with Javascript or jQuery ?? Javascript redirect 如何使用javascript将表单验证中的表单验证重定向到带有MySQL查询的PHP网页到另一个页面 - How to redirect with form validation in javascript to PHP webpage with MySQL query to another page 如何最好地在不使用Javascript的情况下重定向网页? - How best to redirect a webpage without using Javascript? 如何使用Javascript中的网址数组重定向网页? - How to redirect a webpage using an array of urls in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM