在按钮上打开另一个选项卡单击并重定向到另一个html
我知道也有类似的问题,但答案和建议对我不起作用,我无法理解错误 单击一个按钮,我想在一个新选项卡中加载另一个HTML。当我尝试“www.google.com”时,我就能做到。但是当我尝试加载我拥有的HTML时,我无法这样做 以下是相关的html代码:在按钮上打开另一个选项卡单击并重定向到另一个html,html,angularjs,mean-stack,Html,Angularjs,Mean Stack,我知道也有类似的问题,但答案和建议对我不起作用,我无法理解错误 单击一个按钮,我想在一个新选项卡中加载另一个HTML。当我尝试“www.google.com”时,我就能做到。但是当我尝试加载我拥有的HTML时,我无法这样做 以下是相关的html代码: <div id="button"> <a href="www.google.com" target="_blank"><input type="button" value="Visualisati
<div id="button">
<a href="www.google.com"
target="_blank"><input type="button" value="Visualisation"></a><!-- THIS WORKS -->
<form action="/Users/tarun/Work/marchDemo/public/views/tree_custom.html"
target="_blank">
<input type="submit"
value="Go to Google" />
</form><!-- THIS Fails -->
<input type=button
onClick="location.href='tree_custom.html'"
value='click here'
target="_blank"><!-- THIS Fails -->
</div>
如果您使用的是Angular,我建议使用。然后,您可以将控制器中定义的方法绑定到
ng click
。这将在用户单击按钮时打开一个包含所需url的新选项卡
body.html
<div ng-controller="exampleCtrl as ctrl">
<button ng-click="ctrl.directToGoogle()"></button>
</div>
index.js
angular.module('exampleModule', [])
.controller('exampleCtrl', ['$scope', '$window',
function ($scope, $window) {
$scope.directToGoogle = function () {
$window.open('https://www.google.com', '_blank')
}])
body.html
index.js
angular.module('exampleModule',[])
.controller('exampleCtrl',['$scope','$window',
函数($scope$window){
$scope.directToLogle=函数(){
$window.open($window)https://www.google.com“,”空白“)
}])
这将是一个简单而精心设计的示例,说明如何将方法绑定到
ng click
,并执行您在前面的问题中描述的操作。如果您使用Angular,我建议使用。然后您可以将控制器中定义的方法绑定到ng click
。当e用户单击您的按钮
body.html
<div ng-controller="exampleCtrl as ctrl">
<button ng-click="ctrl.directToGoogle()"></button>
</div>
index.js
angular.module('exampleModule', [])
.controller('exampleCtrl', ['$scope', '$window',
function ($scope, $window) {
$scope.directToGoogle = function () {
$window.open('https://www.google.com', '_blank')
}])
body.html
index.js
angular.module('exampleModule',[])
.controller('exampleCtrl',['$scope','$window',
函数($scope$window){
$scope.directToLogle=函数(){
$window.open($window)https://www.google.com“,”空白“)
}])
这将是一个简单而精心设计的示例,演示如何将方法绑定到ng click
,并执行您在前面的问题中描述的操作。您可以使用onclick=“window.open('tree_custom.html')”
和target=“\u blank”
而不是使用location.href
<div id="button">
<a href="www.google.com"
target="_blank"><input type="button" value="Visualisation"></a><!-- THIS WORKS -->
<form action="/Users/tarun/Work/marchDemo/public/views/tree_custom.html"
target="_blank">
<input type="submit"
value="Go to Google" />
</form><!-- THIS works -->
<input type=button onclick="window.open('tree_custom.html')"
value='click here'
target="_blank"><!-- THIS WORKS -->
</div>
检查工作日志:您可以使用onclick=“window.open('tree\u custom.html')”
和target=“\u blank”
来代替location.href
<div id="button">
<a href="www.google.com"
target="_blank"><input type="button" value="Visualisation"></a><!-- THIS WORKS -->
<form action="/Users/tarun/Work/marchDemo/public/views/tree_custom.html"
target="_blank">
<input type="submit"
value="Go to Google" />
</form><!-- THIS works -->
<input type=button onclick="window.open('tree_custom.html')"
value='click here'
target="_blank"><!-- THIS WORKS -->
</div>
检查正在工作的plunker:hi,谢谢:)我尝试了这个方法,但它不起作用。即使是你共享的plnkr示例也给出了一个内部服务器错误。tree\u custom.html我只对第三个输入按钮使用了重定向。你在哪里托管了你的html文件?@Tarun我刚刚读了这个评论,如果你遇到了内部服务器错误,那么埃尼尔说,你需要主持你的婚礼files@ShermanHui还有anil-谢谢..是的。我不得不把它放在另一个文件夹中,因为它里面嵌入了javascript。谢谢你们两个。嗨,谢谢:)我尝试了这个方法,但不起作用。即使是你共享的plnkr示例也给出了一个内部服务器错误。tree_custom.html我使用了重定向仅适用于第三个输入按钮。您在哪里托管了您的HTML文件?@Tarun我刚读到这条评论,如果您遇到内部服务器错误,那么正如Anil所说,您需要托管您的HTML文件files@ShermanHui还有anil-谢谢..是的。我不得不把它放在另一个文件夹里,因为它里面嵌入了javascript。谢谢你们两个你能分享一个你是什么样的人的小例子吗saying@Tarun我在我的回答中添加了一个例子,我希望这能澄清我所说的。你能分享一个关于你是什么的小例子吗saying@Tarun我在回答中添加了一个例子,我希望这能澄清我的意思。