Javascript 如何在asp按钮上调用以下脚本单击
我想在单击按钮时调用脚本,而不是在Javascript 如何在asp按钮上调用以下脚本单击,javascript,asp.net,facebook-javascript-sdk,Javascript,Asp.net,Facebook Javascript Sdk,我想在单击按钮时调用脚本,而不是在div中默认使用以下脚本 <div class="fb-login-button" data-show-faces="true" data-width="400" data-max-rows="1"> </div> <script language="javascript" type="text/javascript"> window.fbAsyncInit = functio
div
中默认使用以下脚本
<div class="fb-login-button" data-show-faces="true" data-width="400" data-max-rows="1">
</div>
<script language="javascript" type="text/javascript">
window.fbAsyncInit = function () {
FB.init({
appId: 'xxxxxxxxxxx',
status: true,
cookie: true,
xfbml: true
});
};
(function (d) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
</script>
window.fbAsyninit=函数(){
FB.init({
appId:'xxxxxxxxxx',
状态:正确,
曲奇:是的,
xfbml:对
});
};
(职能(d){
var js,id='facebook jssdk',ref=d.getElementsByTagName('script')[0];
if(d.getElementById(id)){
返回;
}
js=d.createElement('script');
js.id=id;
js.async=true;
js.src=“//connect.facebook.net/en_US/all.js”;
ref.parentNode.insertBefore(js,ref);
}(文件);
有人能帮助我如何在asp按钮单击事件中调用或执行此脚本。Edit
您的代码不完整,我更新了代码,这在我的域上有效,因此,它必须在您的域上也有效
将此js代码放入a.js文件中,按下按钮时会调用:
window.fbAsyncInit = function() {
FB.init({
appId : 'your_app_id', // App ID
channelUrl : 'your_app_domain', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Here we subscribe to the auth.authResponseChange JavaScript event
FB.Event.subscribe('auth.authResponseChange', function(response) {
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected') {
// logged into the app
alert('logged');
} else if (response.status === 'not_authorized') {
// In this case, the person is logged into Facebook, but not into the app
alert('non logged');
FB.login();
} else {
// not logged into Facebook
alert('non logged everywhere');
FB.login();
}
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
然后将此代码放到要调用它的页面上,记住fb root div和fb需要的所有其他内容:
<div id="fb-root"></div>
<div class="fb-login-button" data-show-faces="true" data-width="400" data-max-rows="1">
</div>
<button onClick="loadit()">ZzZzz</button>
<script type="text/javascript">
function loadit(){
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'a.js';
head.appendChild(script);
}
ZzZzz
函数loadit(){
var head=document.getElementsByTagName('head')[0];
var script=document.createElement('script');
script.type='text/javascript';
script.src='a.js';
head.appendChild(脚本);
}
结束编辑
您可以通过以下方式从javascript加载脚本(例如我们称为文件a.js):
您将把js代码放在文件a.js中
检查它是否有效或需要一些改进
<button onClick="loadit()">ZzZzz</button>
<script type="text/javascript">
function loadit(){
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'a.js';
head.appendChild(script);
}
</script>
ZzZzz
函数loadit(){
var head=document.getElementsByTagName('head')[0];
var script=document.createElement('script');
script.type='text/javascript';
script.src='a.js';
head.appendChild(脚本);
}
(你不需要隐藏应用程序id,它通过js可见,除了你之外,其他人都不能在指定的域之外使用它。)Hi但是登录屏幕没有出现,即使我在脚本中包含了它file@Learner控制台错误?您的代码在正常情况下工作吗?我没有使用div登录,只是检查了登录页面是否即将到来,没有控制台errors@Learner请检查帖子的更新(你发布的代码不完整)