How To Use The <a> To Make Links & Open Them ... - HTML

文章推薦指數: 80 %
投票人數:10人

The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank" , the ... SkiptocontentHTML  /  HTMLAnchors:Here’sHowToCreateLinksForFastNavigation  /  HowToUsea(ForCreatingHyperlinks)InHTML/HowToUseTheToMakeLinks&OpenThemWhereYouWant!Disclosure:Yoursupporthelpskeepthesiterunning!Weearnareferralfeeforsomeoftheserviceswerecommendonthispage.LearnmoreAttributeofHowToUsea(ForCreatingHyperlinks)InHTMLWhatdoesHowToUseTheToMakeLinks&OpenThemWhereYouWant!do?Specifiesthecontextinwhichthelinkedresourcewillopen.Contents1CodeExample2Framesdeprecated;onlyuse_blank3Defaulttarget4atarget=”_blank”OpeninNewBrowserTab(orWindow)4.1WhyOpeninaNewBrowser?4.2OpenAllExternalLinksinaNewTabwithJavaScript4.3Reasonsnottouse`target=”_blank”5ValuesofthetargetAttribute6AllAttributesoftheanchorElement7BrowserSupportfortargetCodeExampleThehomepagewillopeninanothertab.Thehomepagewillopeninanothertab.Framesdeprecated;onlyuse_blankTheonlycurrentlyrelevantvalueoftargetis_blank.Theothervaluesoftargetwereusedtospecifyspecificframes.However,frameshavebeendeprecatedinHTML5.DefaulttargetIfnotargetisspecified,thelinkwillopeninthecurrentcontext,unlesstheuserorbrowserspecifiesotherwise.atarget=”_blank”OpeninNewBrowserTab(orWindow)Thetargetattributespecifieswherethelinkeddocumentwillopenwhenthelinkisclicked.Thedefaultisthecurrentwindow.Iftarget="_blank",thelinkeddocumentwillopeninanewtabor(onolderbrowsers)anewwindow.WhyOpeninaNewBrowser?Themostcommonreasontouse`target=”_blank”issothatoffsitelinksopeninaseparatetab.Thisallowsausertoclickonareferenceandcomebacktoitlaterwithoutleavingthecurrentpage.Itkeepsvisitorsonyoursitelongerandimprovesmostofyourmetrics:bouncerate,conversion,pagesvisited.OpenAllExternalLinksinaNewTabwithJavaScriptYoudon’tneedtomanuallyaddtarget="_blank"toeverylinkonyoursite.Ifyoulinkoutalot(whichyoushoulddo),itiseasytoaddsomeJavaScriptcodetoyoursiteandturnallexternallinksinto_blanklinksautomatically.jQuery(document.links).filter(function(){returnthis.hostname!=window.location.hostname;}).attr('target','_blank');(Youcanseeaslightlymodifiedformofthiscodeinactiononeverypageofthiswebsite.)ThistrickrequiresjQuery,butthereisagoodchanceyouareusingitalready.Itisusedinthemostpopularframeworksandcontentmanagementsystems,includingWordPress,Drupal,andTwitterBootstrap.IfyouneedtodoitwithoutjQuery,thatcanbedoneaswell.Hereisa“plainJavaScript”version:functionexternalLinks(){for(varc=document.getElementsByTagName("a"),a=0;aHTMLTag1,252views977views742viewsImgHeightInHTML:HowNotToUseTheHeightAttribute583viewsInputPattern:UseItToAddBasicDataValidationInHTML5520viewsWeusecookiestoensurethatwegiveyouthebestexperienceonourwebsite.Ifyoucontinuetousethissitewewillassumethatyouarehappywithit.Ok



請為這篇文章評分?