从JavaScript调用href [英] Call href from JavaScript
问题描述
这是与这一个相同的问题,我再也不能回答了,所以我用我的帐户重新发布它。
很抱歉这个烂摊子。
This is the same question as THIS ONE, I can't answer that anymore, so I'm re-posting it with my account.
Sorry for the mess.
我需要一个页面加载激活的Greasemonkey脚本像'javascript:FUNCTION'这样的href链接。
我见过这段代码:
I need a Greasemonkey script that on a page load activates a href link like 'javascript:FUNCTION'. I've seen this code:
<script language="Javascript" type="text/javascript">
function somescript() {
window.location.href = document.getElementById('ololo').href;
}
</script>
<a href="javascript:alert('test');" id="ololo">test</a>
<br />
<a href="javascript:somescript()">click me</a>
并且,即使在使用onload时它在本地页面上工作,但当我使用它时它不起作用在我的脚本中使用它。
and, while it works on a local page even when using onload, it doesn't work when I use it in my script.
将代码从html页面的主体转移到Greasemonkey脚本时,可能会遗漏一些东西。
Probably I'm missing something when transferring the code from the body of an html page to a Greasemonkey script.
我希望这次问题更清楚,请原谅我的任何误解,但我仍然是JS的初学者。
I hope this time the question is more clear, excuse me for any misunderstanding, but I'm still a beginner with JS.
推荐答案
像这样解决:
window.location=document.getElementById('foo').href;
感谢大家回答。
这篇关于从JavaScript调用href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!