i am showing the linked in share button using this :
<script type="text/javascript" src="http://platform.linkedin.com/in.js"></script>
<script type="IN/Share" data-url="http://www.example.com"></script>
The share button is displaying and working as it should, but when i am loading more content by ajax, share button is not displaying, just this 2 scripts are there. I searched their API but couldn't find any way. Is there any way we can call for share button by any javascript or jquery function?
Please help.
Thanks in advance.
i finally found it myself, this is how we can do it :
$.getScript("http://platform.linkedin.com/in.js?async=false", function success() {
IN.init({
api_key: "API KEY HERE"
});
});
Related
I want to open a bootstrap modal on page load. but my problem is that at every page refresh, it do gets launch but I want to display it only single time when user redirect on the that page.
Can anyone suggest me how to do that?
Thanks in advance.
Can it be possible in this way while on a page load?
<script type="text/javascript">
$(window).on('load',function(){
$('#myModal').modal('show');
});
</script>
Hoping that you have used bootstrap modal box as you haven't mentioned the code so.
Yes there are many ways to do that... You can send $_GET parameter in url Something like this:-
Suppose Url :- localhost/modal?open=modal
Now in Jquery You can do like this:-
<script> //not forget to add ready function
<?php if(isset($_GET['open']) && $_GET['open']=="modal"){ ?>
$("#somemodalid").modal('show') //open modal here
<?php } ?>
</script>
Hope it helps!
I need to be about to tell a page when it loads which jquery tab to use as the selected / active tab -- I've tried all the solutions I've found here, and have searched elsewhere extensively, but I'm handicapped by knowing very little about js and jquery. I'm also under a severe time crunch, so if anyone can help me I would be extremely grateful.
Here is my code:
In the page head section, I have:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-ui.js"></script>
<script type="text/javascript" src="jquery-tabs.js"></script>
and
<script>$(document).ready(function()
$("#tabs > ul").tabs();</script>
In the body, I have the tab div set up, with the tabs as li items (sample below), and everything works fine except that I can't seem to select a tab programmatically.
li class="tabstuff"><a class="tabstuff" href="#tab1"><span>First Tab</span></a></li>
I haven't even been able to force my second tab to select on page load when I've tried using the code I saw in one of your question posts:
First I got the index of the tab I wanted (which I know worked, because I displayed it to myself using an alert box), using this:
var index = $('#tabs a[href="#tab2"]').parent().index();
Then I tried each of these two methods (separately):
$("#tabs").tabs("option", "active", index);
I also tried:
$('#tabs').tabs('select', index);
Nothing works, and I don't know enough about jquery to see where I'm going wrong.
A second issue is how to tell the function which tab to select and display as active on page load. I can pass in a post or get variable, but I've tested code I found that says I can use this:
var qry = window.location.search;
if (qry.indexOf("showlist=yes") > 0) {
//I added an alert box here and it never got triggered
}
to check for a post or get variable, and that doesn't seem to work either.
My web page builds the html via php, but I don't yet understand enough about triggering a jquery function to know how to do that anywhere except on page load or an onclick/onchange event.
Thanks for any help anyone can give!
In order to select a different tab than the first you have to do
$("#tabs").tabs({ active: 2 });
Where 2 can be changed by any index you want
I am new to jQuery AJAX function. I want to redirect my user to a webpage when he clicks a button. Please do not tell me to target the button to the webpage as I have to do some working in the php file... My current code is :-
TEST.html file :-
<html>
<head>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("test2.php");
});
});
</script>
</head>
<button>Get External Content</button>
<div id="div1"></div>
</html>
Now my test2.php file is the following :-
<?php header("Location:http://google.com"); ?>
I am a beginner in AJAX jQuery. So, please do not downvote my post although it may sound silly. My code, for obvious reasons is not working. Please help me. Thanks in advance. Any help will be appreciated.
You cant redirect with an AJAX call. You can either create a simple link or link to a PHP page which then redirects the user on. Using AJAX will only let you manipulate this page you are on.
Of course, you can always redirect with simple Javascript as well.
window.location = '/my_url.php';
EDIT: In response to your comment question, what I would do is use the .get() function with the data parameter, check what has been returned from the PHP page if server side validation is required and then if I am happy with the result, redirect.
If no server side validation is needed, there is no need for AJAX.
Look at it this way: AJAX is requesting and reading the .php file. When AJAX sees the header("Location: ...") line, it redirects the AJAX request. Put simply, AJAX can't be used for redirects.
You can use the complete callback to redirect the user after the AJAX query has completed like so:
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("test2.php",
complete: function(){
window.location = 'http://new_url';
}
);
});
});
That being said if you just want to redirect a user on a button click there are better ways to do that.
$("#div1").load("test2.php");
appends the contents which are
returned from test2.php , it will not redirect. The test2.php should return a link and populate the div with the link. Then write a callback on ajax success which will
redirect using window.location = target , the target being the link which was dynamically loaded in the div1
I want to execute a php code when a user click on a given link , i've tried the following code
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
function doSomething() {
$.get("up.php");
return false;
}
</script>
</head>
<body>
<center>
Click Me!
</center>
</body>
</html>
where up.php is a php code that implement android GCM mechanism similer to the one in the link : GCM with PHP (Google Cloud Messaging)
but unfortunately when the link is clicked nothing happens , the php code not executed ,and only the url of the page change form *****.com/test.html to *****.com/test.html# , and by the way I've tested the php code and its works fine so it is not a problem in php code , so what i have missed here? why the code is not executed?
i found the solution , the problem that the jquery library is not included probably in my code
you are using jquery. $.get() will be something like below.
$.get('ajax/test.html', function(data) {
$('.result').html(data);
alert('Load was performed.');
});
for further help check http://api.jquery.com/jQuery.get/
Sometimes, you may need to call some JavaScript from within a link. Normally, when user click on a link, the browser loads a new page (or refreshes the same page).
This might not always be desirable. For example, you might only want to dynamically update a form field when the user clicks a link.
To prevent the load from refreshing, you could use the JavaScript void() function and pass a parameter of 0 (zero) as below.
<a href="JavaScript:void(0);" onclick="return doSomething(); " />Click Me!</a>
Now if you want to use href="#", make sure onclick always contains return false; at the end.
OR
Use href="javascript:void(0)"
You can also use jQuery Load
function doSomething() {
$('#result').load('up.php', function() {
alert('Load was performed.');
});
}
When you are using Jquery should be :
function doSomething(){
$.get('up.php', function(data) {
$('.data').html(data);
});
}
Link
To stop page refreshing, you can use the javascript void() function and pass parameter of 0.
Click Me!
<div class="data"></div>
This div is used to display up.php result.
Ok start of by using fire bug and watch the console and network panels
Ensure the browser is trying to get something and not returning a 404 or a php error on the get
Look into prevent default http://api.jquery.com/event.preventDefault/
To stop the original link functionality working
If you still want them to move to the link use a window location or...
Look into bootstrap link buttons
http://twitter.github.com/bootstrap/base-css.html#buttons
( the link button )
I'm currently working on a website and I would like to be able to do the following:
when clicking one of the links from the sideMenu the only thing I would like to change would be the content of my contentMain div and nothing else(page layout/design/etc)
Could anybody give me some general pointers on how I could achieve this in php?
Thank You in advance :D
This is a client-side change that cannot be accomplished using PHP. PHP is evaluated on the server-side, so once the page is loaded for the user, it has no control over what the user sees (unless you use client-side code to call PHP).
To accomplish this, you will need to use Javascript and/or jQuery.
Reference: https://developer.mozilla.org/en/JavaScript/
jQuery: http://jquery.org/
iFrame, frameset or AJAX all work for your case depending on what you are actually trying to achieve.
For AJAX calls (the most modern way out of the three that relies on Javascript) you can use a library such as jQuery.
http://api.jquery.com/category/ajax/
You can use ajax for this one. Using jQuery to detect the click on the link or use normal JavaScript onClick function. Then do the things like you want.
<a href="" id="my_link">My link<a>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#my_link').click(function(){
jQuery.ajax({
url: 'ajax page need to be called',
success: function(data) {
//do your operations on success
}
});
});
});
</script>
You can get more details on :
jQuery
jQuery Ajax
Hope this helps you