是否有可能将HTML重定向到JavaScript函数? [英] Is it possible to redirect HTML to javascript function?
问题描述
我有以下HTML代码:
I have the following HTML code :
<div class="action-button">
<a href="/wp-login.php?loginFacebook=1&redirect=http://blabla.com" class="MyButton">Hello
</a>
</div>
是否可以在重定向时调用javascript函数(存储在文件中)而不是重定向到具体URL?
Is it possible to call a javascript function (stored in a file) while redirecting instead of redirecting to a specific URL ?
javascript文件与其他域名在同一个域中。
The javascript file is in the same domain as the rest.
谢谢。 p>
Thank you.
推荐答案
您可以使用查询字符串来完成此操作。例如
You can do it with a query string. for example
<a href="http://blabla.com/mypage.html?callfunction=1">Hello</a>
然后在它重定向到(mypage.html)的页面上,您可以像
then on the page it redirects to (mypage.html) you'd do something like
<script>
if (getParameterByName('callfunction') == 1)
callMyFunction1();
</script>
您也可以通过querystrings传递参数。
You could also pass parameters via querystrings.
有关querystrings的更多信息,请参阅 -
如何在JavaScript中获取查询字符串值?
For more info on querystrings see-- How can I get query string values in JavaScript?
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
这篇关于是否有可能将HTML重定向到JavaScript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!