I have a piece of code to log user out from linkedin and its not working :(
any help will be greatly appreciated.
Logout code
<html>
<head>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: mykey
authorize: true
</script>
<script type="text/javascript">
try {
IN.User.logout();
} catch (err) {
console.log(err);
}
setTimeout("goToHome()", 10000);
function goToHome() {
location.href="index.php";
}
</script>
</head>
</html>
console log
TypeError
arguments: Array[2]
get message: function () { [native code] }
get stack: function () { [native code] }
set message: function () { [native code] }
set stack: function () { [native code] }
type: "non_object_property_call"
__proto__: Error
Best regards,
Pawan
It looks like you are trying to call IN.User.logout() before the LinkedIn JavaScript platform has completely loaded. You should run the code only once you are sure the library is loaded, via either the onLoad value in the platform bootstrap section:
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: mykey
authorize: true
onLoad: onLoad
</script>
<script type="text/javascript">
function onLoad() {
try {
IN.User.logout();
} catch (err) {
console.log(err);
}
setTimeout("goToHome()", 10000);
}
function goToHome() {
location.href="index.php";
}
</script>
Alternatively, use one of the event callbacks:
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: mykey
authorize: true
</script>
<script type="text/javascript">
IN.Event.onOnce(IN, 'systemReady', function() {
try {
IN.User.logout();
} catch (err) {
console.log(err);
}
setTimeout("goToHome()", 10000);
});
function goToHome() {
location.href="index.php";
}
</script>
Related
I'm trying to use JQuery encapsulation and have created file under my js directory, js/modules.js
"use strict";
console.log("im in modules.js");
var xxModule = function() {
console.log("im in xxModule");
var form = $('#module-form');
var processForm = function() {
console.log("im in processForm");
form.validate({
rules: {
name: {
required: true
}
},
messages: {
name: "please enter a valid module name"
}
});
}
return {
processModuleForm: function() {
console.log("im in return");
processForm();
},
};
}();
in my php blade file, I'm calling it in the document ready function as
<script src="{{ asset('js/modules.js') }}" type="text/javascript"></script>
<script>
$( document ).ready(function() {
console.log("im in ready");
xxModule.processModuleForm();
});
</script>
when the page is rendered its throwing error, jQuery.Deferred exception: xxModule is not defined #http://dev.projects/modules/create:82:3 as below
im in modules.js modules.js:99:9
im in xxModule modules.js:102:11
im in ready create:81:17
jQuery.Deferred exception: xxModule is not defined #http://dev.projects/modules/create:82:3
e#https://code.jquery.com/jquery-3.5.1.min.js:2:30005
l/</t<#https://code.jquery.com/jquery-3.5.1.min.js:2:30307
setTimeout handler*l/<#https://code.jquery.com/jquery-3.5.1.min.js:2:30516
c#https://code.jquery.com/jquery-3.5.1.min.js:2:28294
fireWith#https://code.jquery.com/jquery-3.5.1.min.js:2:29039
fire#https://code.jquery.com/jquery-3.5.1.min.js:2:29075
c#https://code.jquery.com/jquery-3.5.1.min.js:2:28294
fireWith#https://code.jquery.com/jquery-3.5.1.min.js:2:29039
ready#https://code.jquery.com/jquery-3.5.1.min.js:2:32012
B#https://code.jquery.com/jquery-3.5.1.min.js:2:31791
EventListener.handleEvent*#https://code.jquery.com/jquery-3.5.1.min.js:2:32160
#https://code.jquery.com/jquery-3.5.1.min.js:2:220
#https://code.jquery.com/jquery-3.5.1.min.js:2:225
undefined jquery-3.5.1.min.js:2:31560
Uncaught ReferenceError: xxModule is not defined
<anonymous> http://dev.projects/modules/create:82
jQuery 13
create:82:3
please can you help with this issue?
thanks
I've been trying to define a function that calls a jquery plugin that works without a selector
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mouse0270-bootstrap-notify/3.1.7/bootstrap-notify.min.js"></script>
<script>
$.notify({
// options
message: 'Hello World'
}, {
// settings
type: 'danger'
});
</script>
This first one works as intended,
but when trying this next setup
<script>
function sendNotification() {
$.notify({
// options
message: 'Hello World'
}, {
// settings
type: 'danger'
});
}
</script>
it throws a $.notify not defined
enerytime when i click the "send" button(blind the NativeMessaging method),it will launch a new instance , i just want make it only one instance with the connect running correctly,sot that i can send message sustainable.
Thanks a lot!
That's my background.js code:
var port = null;
console.log("visited test!");
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.type == "launch") {
console.log("visited 333!");
connectToNativeHost(request.message);
}
return true;
});
// chrome.runtime.onMessage.addListener(function(msg) {
// console.log("Received" + msg.text);
// });
//onNativeDisconnect
function onDisconnected() {
console.log(chrome.runtime.lastError);
console.log('disconnected from native app.');
port = null;
}
function onNativeMessage(message) {
console.log('recieved message from native app: ' +JSON.stringify(message));
}
//connect to native host and get the communicatetion port
function connectToNativeHost(msg) {
var nativeHostName = "com.example.test";
// console.log(typeof(nativeHostName));
// console.log(nativeHostName);
//port = chrome.runtime.connectNative(nativeHostName);
port = chrome.runtime.sendNativeMessage(nativeHostName,{ message: msg });
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
port.postMessage({ message: msg });
}
That's my content.js code:
var launch_message;
document.addEventListener('myCustomEvent', function (evt) {
console.log("visited!");
chrome.runtime.sendMessage({ type: "launch", message: evt.detail }, function (response) {
console.log(response);
// console.log("visited here!");
});
}, false);
That's my test HTML file code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Communicate with native app</title>
<script>
function startApp() {
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent('myCustomEvent', true, false, "im information");
// fire the event
document.dispatchEvent(evt);
console.log("The button was clicked!");
}
</script>
</head>
<body>
<button type="button" onclick="startApp()" id="startApp">startApp</button>
</body>
</html>
and i write the demo native application use C# language.
I downloaded the js.cookie.js library and installed on website but for some reason it's not setting any cookie. Here's my code:
<script src="/Scripts/js.cookie.js"></script>
<script type="text/javascript">
$(document).ready(function () {
if ($.Cookies.get('modal_shown') == null) {
$.Cookies.set('modal_shown', 'yes', { expires: 14 });
$('#myModal').foundation('reveal', 'open')
}
});
//$(document).ready(function () { $('#myModal').foundation('reveal', 'open') });
What am I doing wrong?
BTW, this is put in an asp.net 4.0 masterpage.
How made JavaScript cohesion work? Lets me explain better: I have my index page that call models forms with jquery dialogs, but I don't want put all javascript in index page, instead I want the jquery separate for page.
Model form
This work
INDEX PAGE
#section Scripts
{
<link href="#Url.Content("~/Content/themes/base/minified/jquery-ui.min.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready
(
function () //<--I dont want this function here
{
Alert1();
}
$(".Create").live
(
"click", function (e) {
var url = $(this).attr('href');
$("#dialog-view").dialog
(
{
title: 'Create new User',
autoOpen: false,
resizable: false,
height: 600,
width: 600,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
open: function (event, ui) {
$(this).load(url);
},
buttons:
{
"Cancel": function ()
{
$(this).dialog("close");
},
"Save": function ()
{
$(this).dialog('close');
}
},
close: function (event, ui) {
$(this).dialog('close');
}
}
);
);
function Alert1() //<--I dont want this function here
{
alert("Star!");
}
</script>
}
How should work
INDEX PAGE
#section Scripts
{
<link href="#Url.Content("~/Content/themes/base/minified/jquery-ui.min.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready
(
$(".Create").live
(
"click", function (e) {
var url = $(this).attr('href');
$("#dialog-view").dialog//<--Only opening dialogs
(
{ ....
);
</script>
}
And model forms with you specifics javascripts
#section Scripts
{
<link href="#Url.Content("~/Content/themes/base/minified/jquery-ui.min.css")" rel="stylesheet" type="text/css" />
<script src="#Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready
(
function ()
{
Alert1();
}
);
function Alert1()
{
alert("Star!");
}
</script>
}
Actually, when I made it the model javascript don't work.
I'm using Entity-framework, thanks for everything.
SOLUTION
<script type="text/javascript">
$(document).ready
(
function ()
{
Alert1();
}
);
function Alert1()
{
alert("Star!");
}
</script>
Just remove the section "Scripts" {} from the Model file. You must have the renderSection("scripts") method only called within the Index page, which will only render the scripts files when the Index page loads and ignore any new script loaded.
<script type="text/javascript">
$(document).ready
(
function ()
{
Alert1();
}
);
function Alert1()
{
alert("Star!");
}
</script>