如何在新选项卡中的随机链接中打开HTML按钮

时间:2016-04-30 15:43:24

标签: html button tabs

所以我创建了一个无用的网站,我需要创建一个按钮,将人们引导到新标签中的随机网站。我已经有了随机链接按钮代码,但似乎无法用新的选项卡代码添加它。

样品

var randomlinks=new Array(10)

 randomlinks[0]="http://ducksarethebest.com/"
 randomlinks[1]="http://cant-not-tweet-this.com/"
 randomlinks[2]="http://just-shower-thoughts.tumblr.com/"
 randomlinks[3]="http://www.fallingfalling.com/"
 randomlinks[4]="http://www.partridgegetslucky.com/"
 randomlinks[5]="http://ducksarethebest.com/"
 randomlinks[6]="http://cant-not-tweet-this.com/"
 randomlinks[7]="http://just-shower-thoughts.tumblr.com/"
 randomlinks[8]="http://www.fallingfalling.com/"
 randomlinks[9]="http://www.staggeringbeauty.com/"
 randomlinks[10]="http://www.trypap.com/"

function randomlink(){
window.location=randomlinks[Math.floor(Math.random()*randomlinks.length)]
}

HTML

    <form method="post">
    <p><input type="button" name="B1" value="Random Link >>" onclick="randomlink()""window.open'"></p> 
</form>
    or
    <a href="javascript:randomlink()">Random Link</a>

1 个答案:

答案 0 :(得分:0)

您需要使用[TestClass] public class ApplicationVariablesTests { public class FakeApplicationSettings : IApplicationSettings { Dictionary<string,object> Application = new Dictionary<string,object>(); public string this[string keyToReturn] { get { return Application[keyToReturn]; } set { Application[keyToUpdate] = value; } } } [TestMethod] public void Should_Update_General_Settings() { //Arrange SomeUtilityClass.Application = new FakeApplicationSettings(); SomeUtilityClass.UpdateApplicationVariable("GeneralSettings", new GeneralSettings() { NumberDecimalPlaces = 2 }); //Act GeneralSettings settings = SomeUtilityClass.GetApplicationVariable("GeneralSettings") as GeneralSettings; //Assert Assert.IsNotNull(settings); Assert.AreEqual(2, settings.NumberDecimalPlaces); } } 代替window.open(url)

window.location(url)表示:设置当前标签的网址。

参考:Don't mock HttpContext

示例:(不支持stackoverflow导致沙盒框架)

&#13;
&#13;
window.location(url)
&#13;
var randomlinks = [];
randomlinks[0]="http://ducksarethebest.com/";
randomlinks[1]="http://cant-not-tweet-this.com/";
randomlinks[2]="http://just-shower-thoughts.tumblr.com/";
randomlinks[3]="http://www.fallingfalling.com/";
randomlinks[4]="http://www.partridgegetslucky.com/";
randomlinks[5]="http://ducksarethebest.com/";
randomlinks[6]="http://cant-not-tweet-this.com/";
randomlinks[7]="http://just-shower-thoughts.tumblr.com/";
randomlinks[8]="http://www.fallingfalling.com/";
randomlinks[9]="http://www.staggeringbeauty.com/";
randomlinks[10]="http://www.trypap.com/";

function randomlink(){
  window.open(randomlinks[Math.floor(Math.random()*randomlinks.length)]);
}
&#13;
&#13;
&#13;