我试图在新选项卡中打开一个URL,而不是弹出窗口.我已经看到相关的问题,其中的回答看起来像:
window.open(url,'_blank');
window.open(url);
Run Code Online (Sandbox Code Playgroud)
但是它们都没有为我工作,浏览器仍然试图打开一个弹出窗口.
我正在尝试在用户点击链接时打开新页面.我不能使用Angular 2路由器,因为它没有任何功能可以重定向到外部URL.
所以,我正在使用window.location.href ="...";
HTML代码:
<button (click)="onNavigate()">Google</tn-submenu-link>
Run Code Online (Sandbox Code Playgroud)
打字稿代码:
onNavigate(){
//this.router.navigateByUrl("https://www.google.com");
window.location.href="https://www.google.com";
}
Run Code Online (Sandbox Code Playgroud)
但是如何在新标签中打开它?什么时候使用window.location.href?
我有一个 Python 代码,我使用 Flask 创建一个网页。在主页中,我正在填写一个表单,使用按钮提交,它会根据输入显示一个表格。
我遇到的问题是,一旦我单击按钮提交表单,它就会在同一网页上呈现表格。我想使用 JavaScriptwindow.open()或您建议的任何其他方法创建一个新窗口,以在新窗口中呈现该表格并保持主页不变。我试着环顾四周,但似乎什么也做不了。我已经读过这个问题和这个问题。但这些建议似乎与我正在寻找的不符。
这是我的代码:
Python代码
from flask import Flask, render_template, request,
app = Flask(__name__)
def get_table(user_input):
...
return dict //returns list of dictionaries, for example...
//dict = [{'name':'Joe','age':'25'},
// {'name':'Mike','age':'20'},
// {'name':'Chris','age':'29'}]
@app.route("/")
def home():
return render_template('home.html')
@app.route("/table", methods = ['POST'])
def table():
user_input = request.form['input']
dict_table = get_table(user_input) //return list of dictionaries
return render_template('table.html', dict_table=dict_table)
if __name__ == '__main__':
app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)
首页.html
<!DOCTYPE html>
<html>
<head>
<title>Homepage</title>
</head> …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚是否有办法使用" javascript:location.href " 打开一个新标签.我无法使用其他方法打开链接,因为它需要在加载时获取我网站的某个成员的ID.我也无法创建一个javascript函数,因为我有多个链接要打开.
target="_blank" //didn't work
Run Code Online (Sandbox Code Playgroud)
这是我的一段代码:
<a onclick="javascript:location.href='website.com' + location.search"><a/>
Run Code Online (Sandbox Code Playgroud)
如果还有其他方法可以做到这一点,请告诉我.