方法一://target="_blank"表示保留当前页面,在新标签页打开收集优质网站资源方法二:window.location.hrefwindow.location.href="https://smallpdf.cn";方法三:window.open()//"_blank"表示保留当前页面,Openwindow.open("https://smallpdf.cn","_blank");警告信息问题描述#以上写法,会出现如下警告信息:warningUsingtarget="_blank"withoutrel="noreferrer"isasecurityrisk:见https://html.spec.whatwg.org/multipage/links.html#link-type-noopenerreact/jsx-no-target-blank解决方案#添加属性:rel="noreferrer"原因详解使用target="_blank"打开新标签页时,新页面的window.opener引用上一个页面,使得上一个页面可以控制。例如:当新旧页面在同一个域名下时,在新页面的控制台输入window.opener.alert(1),会发现旧页面弹出消息1。当新旧页面不在同一个域名下时,可以通过window.opener.location.replace更改旧页面的url。所以添加rel="noreferrer"并将opener对象设置为null以防止将来的麻烦。相关链接window对象详细说明window.opener对象详细说明页面跳转passparameter#passparameterpageleta={key:'value'}//序列化参数letastr=JSOS.stringfy(a);leturl='https://learn-anything.cn/search?input='+astr;window.open(url);#接受参数页面:https://learn-anything.cn/search//window.location,存储本页面相关的所有数据letquery=window.location.query;#参数解析方式:consturlTemp=require('url');letparsedUrl=urlTemp.parse(window.location.href,true);letpara=parsedUrl.query.astr;#反序列化得到参数,如果是非序列化参数,直接使用参数,不用这一步leta=JSON.parse(para);5种跳转到相关链接HTML页面的方法!
跳转到HTML页面的5种方法!相关文章