私はこのJavascript関数を呼び出そうとしています。私のボタンを押すと、何もロードされていません。私は自分のボタンのIDを設定しました。 onclickを使用して、関数onLinkedInLoadをロードします。しかし、私はスクリプトをアクティブにするために呼び出す必要はありません機能ですか?誰でも私がここで間違っていることを見ることができますか?JS関数onClickを呼び出す
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<button id="btn">Try Me</button>
<script type="text/javascript">
document.getElementById("btn").onclick = onLinkedInLoad;
</script>
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: myKey
authorize: true
onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
// Setup an event listener to make an API call once auth is complete
function onLinkedInLoad() {
IN.Event.on(IN, "auth", shareContent);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to share content on LinkedIn
function shareContent() {
// Build the JSON payload containing the content to be shared
var payload = {
"comment": "Check out developer.linkedin.com! http://linkd.in/1FC2PyG",
"visibility": {
"code": "anyone"
}
};
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(JSON.stringify(payload))
.result(onSuccess)
.error(onError);
}
</script>
</body>
</html>
アップデート: 私は私のコンソールでこれを取得する:
18 Uncaught ReferenceError: onLinkedInLoad is not defined
www.linkedin.com/uas/js/userspace?v=0.0.1191-RC8.56309-1429&apiKey=myKey&authorize=true&onLoad=onLinkedInLoad&secure=1&:
22 Uncaught Error: You must specify a valid JavaScript API Domain as part of this key's configuration.
私も、私の中でAPIKEYをパット。私はここでコードを "myKey"に置き換えました。私も.addEventListener('click', onLinkedInLoad)
で試しましたが、何も起こりません。
コンソールのエラーを確認しましたか? –
'.onclick = onLinkedInLoad'の代わりに.addEventListener( 'クリック'、onLinkedInLoad)' – mpallansch
あなたは –