call javascript link on pageload - php

I have a link on my page, and when I click on this it opens a login popup. This works after click on the link.
I want that on page load. I have wasted lots of time on this but nothing works.
<a id="onestepcheckout-login-link" href="javascript:void(0);"><?php echo $this->__('Already registered? Click here to login.'); ?></a>
This code I am using. Right now is working onclick but I want this on page load.
Please help.

I just did a simple one.This will help you.Just check it http://jsfiddle.net/ArLKy/8/

There's the onload event of the <body> tag:
<body onload="document.getElementById('onestepcheckout-login-link').onclick()">
Here's a cleaner method:
window.addEventListener("load", function()
{
OpenLoginBox();
});

Related

open a bootstrap modal single time when page load in codeigniter website?

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!

running a php code from a link without redirection

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 )

Change "modal" to something like Jquery "toggle"?

I have a modal that pops up with some information when clicked, here is how it looks:
<a rel="moodalbox 850 300 nofollow" href="<?php echo $infolink;?>"
where $infolink is given a LINK to some page.
So what I want to ask, is it possible somehow to open this NOT in a modalbox like now, but just the information to appear in the site somewhere(no page re-loading)...?
Please can somebody just give me a HINT please?
Thanks
You can use preventDefault() method:
$('a[rel*="moodalbox"]').click(function(event){
event.preventDefault()
var href = $(this).attr('href');
$('#info').text(href)
})
DEMO

php ajax refresh part of page on click

I want to be able to click on a link lower down my PHP page, it send a variable and outputs the result in a <div> tag at the top half of the page.
I've linked to latest jquery, and so far I have this in my <head>:
<script type="text/javascript">
$().ready(function() {
$("#result").load("crimes_result.php");
});
</script>
And in my <body>:
<div id="result"></div>
What I need though, is that the div to be shown and depending on the result of a variable sent by a link the user clicks lower down the page.
like crimes_result.php?id=4334 or crimes_result.php?id=54543
How can I finish my script so it does that?
NOTE: I'm useless in ajax/jquery/javascript
If I understand correctly, simply call .load() from a click event and pass it the href of the link:
HTML:
<a class="loadlink" href="crimes_result.php?id=4334">Click Me<a>
JS:
$(".loadlink").click( function(event) {
event.preventDefault();
$("#result").load($(this).attr("href"));
});
Example: http://jsfiddle.net/jtbowden/ueucL/1/

click a link or click submit without refreshing

i have header, main_content, footer, right, and left content
my right content has a random link
i don't want my right content to be refresh when I click a random link
and the main_content would be the output
is it possible that a web page without refreshing the page when you click a link or click submit button and still you can see the url on your browser what you have clicked? how do to that?
thanks!
There are two ways to do this:
1) Target your form to a hidden iframe
2) use AJAX
Here, try these
Your Link
<input type="submit" onClick"return false;" />
Ajax helps you do exactly that. So the skeleton will work like this
- When you submit a link, that posts to the server side using Ajax and the page does not get refreshed. Ajax is essentially a xmlhttprequest submitted to the backend. You may decide to hand code your own xmlhttprequest or take the jquery route(def, the easiest of the 2. You pick your battles, right?)
Here's some help with using jquery http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
bind an event handler to your element like this:
$('#yourBtn').live('click', function(e){
//do the AJAX thingy
e.preventDefault();
}
Read more about jQuery's AJAX solution
The page does not refresh when you try to call a javascript function
like this:
Your Link
<form action="javascript:func()" method="post">
This answer is based on the title.
click a link (pure javascript):
Your Link
<script type=text/javascript">
function functionName(){
// Do the job...
return false;
}
</script>
click a link (using jQuery):
<a id="myId" href="#"> Your Link </a>
<script type=text/javascript">
$(document).ready(function(){
$("#myId").on("click", function(){
// DO the job...
return false;
});
});
</script>
In other words set a click listener for your link and inside the listener's function return false.
You can avoid the refresh page functionality for the submit button on the same way.
On another stackoverflow discussion.

Categories