我知道这可能看起来很简单,当我第一次尝试时,我自己也这么认为,但事实证明我有问题。这是一个UsersScript,我希望它检查URL是否为“http://orteil.dashnet.org/cookieclicker”,然后做一件事(但不刷新),但如果URL是“http://orteil.dashnet.org/cookieclicker/beta”做这个其他的事情(也不刷新) 。这里是我到目前为止的代码,我只想在“http://orteil.dashnet.org/cookieclicker”时运行“linkb”,在“http://orteil.dashnet.org/cookieclicker/beta”运行时运行“linkc”。如果URL = this {//做到这一点} else {//做到这一点}
var link = document.createElement('a');
link.setAttribute('href', 'http://orteil.dashnet.org/experiments/cookie/');
link.target = 'blank';
link.appendChild(
document.createTextNode('Cookie Clicker Classic')
);
var add = document.getElementsByTagName('div')[1];
add.insertBefore(document.createTextNode('| '), add.lastChild);
add.insertBefore(link, add.lastChild); // all the code so far will load on both pages
var linkb = document.createElement('a');
linkb.setAttribute('href', 'beta');
linkb.target = 'blank';
linkb.appendChild(
document.createTextNode('Try the beta!') //this block will load if the URL is "http://orteil.dashnet.org/cookieclicker"
var linkc = document.createElement('a');
linkc.setAttribute('href', '../');
linkc.target = 'blank';
linkc.appendChild(
document.createTextNode('Live version') // and this will load if the URL is "http://orteil.dashnet.org/cookieclicker/beta"
我曾尝试:
if (window.location = "http://ortei.dashnet.org/cookieclicker/") {
var linkb = document.createElement('a');
linkb.setAttribute('href', 'beta');
linkb.target = 'blank';
linkb.appendChild(
document.createTextNode('Try the beta!')
);
}
else {
var linkc = document.createElement('a');
linkc.setAttribute('href', '../');
linkc.target = 'blank';
linkc.appendChild(
document.createTextNode('Live version')
);
}
我都试过,但有警报()的,当你在弹出推确定,它刷新页面,并再次做了警报。我只是想要它检查它是什么URL并做相应的代码。
如果有人可以想出一些想法,甚至可能是一个解决方案,它将不胜感激。
谢谢,丹尼尔
哇... brainfart ......这个节目如果你不睡36个小时,你会有多糟糕......感谢兄弟们:) –
@ZacktonJochem,如果这解决了你的问题,你应该[勾选此答案旁边的复选标记](http:///meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)。 –
噢,是的,对不起,我再次在37个小时没有睡觉的时候指责它:/ –