[英]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.