要在Angular 7中打开带查询字符串的新标签页,您可以使用window.open()
方法。以下是一个使用JavaScript和Angular 7的代码示例:
openNewTab()
方法,使用window.open()
打开新标签页并传递查询字符串:import { Component } from '@angular/core';
@Component({
selector: 'app-your-component',
templateUrl: './your-component.component.html',
styleUrls: ['./your-component.component.css']
})
export class YourComponent {
openNewTab() {
const queryString = '?param1=value1¶m2=value2'; // 替换为实际的查询字符串
const newTab = window.open('https://example.com/newpage' + queryString, '_blank');
newTab.focus();
}
}
请注意,window.open()
方法的第一个参数是要打开的URL,第二个参数是新标签页的名称(这里使用'_blank'
表示在新标签页中打开)。您可以将查询字符串附加到URL后面。
在这个示例中,我们使用了一个硬编码的查询字符串。您可以根据实际需要将其替换为您自己的查询字符串。
确保在使用window.open()
方法之后使用newTab.focus()
将焦点设置到新标签页,以确保用户能够看到新打开的标签页。