I am trying to make a script which detects clicks on google ads. All events works like onmouseover, out etc except click, focus, mousedown. When i click on google ads it open its ads link but dont run my jquery script on click event. I have tried preventdefault and other functions like that too.
I want to detect click on google ads and parse the iframe width and height to php file when clicked.
$(window).load(function(){
$('iframe').bind('mouseover', function(){
var iframeID = $(this).attr('id');
$(this).contents().find('html').unbind();
$(this).contents().find('html').bind('click', function(){
alert(iframeID);
});
});
});
This is the code run on mouseover but not on click event.
You need to bind the click events on the contents of the iframe untill the contents are loaded completely inside the iframe. Try wrapping the code inside the load event.
$('iframe').load(function() {
var iframeID = $(this).attr('id');
$(this).contents().find('html').unbind();
$(this).contents().find('html').bind('click', function(){
alert(iframeID);
});
});
Capturing the click event of an iFrame is not possible when the content is from another domain.
What you can do is detect the mouse-enter and leave on iframe.
Here is example
<div class="item">
<iframe src="http://www.google.com" width="612" height="344" frameborder="0"></iframe>
</div>
<script type="text/javascript">
$("div.item iframe")
.mouseover(function(){
alert("mouse over");
})
.mouseout(function(){
alert("mouse out");
});
</script>
Related
In below,i am trying to redirect from one page to another page with href attribute is appended to URL link.
<script src="jquery-1.11.3.js"></script>
<script>
$(document).ready(function(){
$('a').click(function(){
var clk=$(this).attr('href');
//alert(clk);
window.location='http://www.shopeeon.com&ver='+clk;
});
});
</script>
Google<br/>
Yahoo<br/>
Rediff<br/>
In above example onclick first i want href(i.e. http://www.google.com,http://www.yahoo.com,..etc) which is stored in 'clk' variable and redirect to another page(i.e. http://shopeeon.com) with our link which is stored in "clk" variable.
In my case when i click on link instead of redirecting to other page with appended link it runs that particular href.
You have to stop its Default behaviour by using .preventDefault()
WORKING FIDDLE
$(document).ready(function(){
$('a').click(function(e){
e.preventDefault();
var clk=$(this).attr('href');
//alert(clk);
//window.location='http://www.shopeeon.com&ver='+clk;
window.location='http://www.shopeeon.com&ver='+encodeURI(clk);
});
});
UPDATE FIDDLE
Better Remove a tag, Have some div tag with data attribute place URL there.
For example,
<script src="jquery-1.11.3.js"></script>
<script>
$(document).ready(function(){
$('a').click(function(){
var clk=$(this).attr('data-href');
//alert(clk);
window.location='http://www.shopeeon.com&ver='+clk;
});
});
</script>
<div data-href="http://www.yahoo.com">Yahoo</div><br/>
$(document).ready(function(){
$('a').click(function(){
var clk=$(this).attr('href');
clk ='http://www.shopeeon.com&ver='+clk;
alert(clk);
$(location).attr("href", clk);
});
})
Google
Click on Google to see what is in url to redirect page
I have this link:
<a id="about-me" class="popup">Info About Me</a>
When clicked is using this jq code to open the info about me in a modal window:
$(document).ready(function(){
$('#all').delegate('a.popup', 'click', function(){
var page = $(this).attr('id');
$('#gr-out').css({ opacity: 0.7, 'width':$(document).width(),'height':$(document).height()}).show();
$('#popup').css({'display': 'block'});
$('#popup').load("../jsfiles/loop.php?page="+ page);
})
$('body').delegate('.hide-it', 'click', function(){
$('.hide-it').hide();
$('#popup').empty();
})
});
(The above works great) Now if I wasn't using modal window and was opening the information in a normal window I would be able to copy my url, send it to a friend and he could access the information with no problem.
Now that I am using a modal window (and the above code) I do not have a url to copy and send.
Is there a way that I can have the url using modal window or the only way is to open the information in a normal window?
If I use this line of code in the above jq can I make it show the page name that is clicked instead of testpage?
window.history.pushState('','','/testpage');
So you want to change the current URI to another one? Did I get that right?
Mozilla: The pushState method
html5demos.com Example
I have the page (index.php) that contain one link with id="t1" and one div id="container".
<a id="t1" title="Users" href="utenti.php">Users</a>
<div id="container">
<!--Where does the contained-->
</div>
When I click the link I get a built-in external page (utenti.php)
This is code of Ajax:
$(document).ready(function(){
$("#t1").click(function(){
//$("#container").hide();
$("#container").load($(this).attr("href"), function(){
$("#container").show();
event.preventDefault();
});
return false;
});
});
and so far all is well, but if I click a link in the page that is included (utenti.php) the page is not incorporated in the same div but is opened in a direct manner.
I tried to put in the file .JS the code Ajax, to recognize the ID of the links transforming into:
$(document).ready(function(){
$("#t1").click(function(){
//$("#container").hide();
$("#container").load($(this).attr("href"), function(){
$("#container").show();
event.preventDefault();
});
return false;
});
$("#click").click(function(){
//$("#container").hide();
$("#container").load($(this).attr("href"), function(){
$("#container").show();
event.preventDefault();
});
return false;
});
});
Where #click is id of the link contained in the page Utenti.php,but even so
I do not incorporate the page in the div.
I also tried to include directly the page with the script inside the page utenti.php but I recognize the first link (which is fine) but everyone else does!(not all other!)
If I understand correctly this system does not include actually the page as would the classic include of PHP.
He gives him also the values already included in the index is more a kind of visualization,only that I haven't understand how to pass the value of the links contained in utenti.php inside the main page index.php.
It should be
$(document).on("click","#t1",function(e){
e.preventDefault();
var href = $(this).attr("href");
$("#container").load(href);
});
If you want links on the page that is opened in the div to also be targeted to the div you can try a delegated click handler on the div itself.
$(document).ready(function () {
$("#t1").click(openLinksInDiv);
$("#container").on("click", "a", openLinksInDiv);
function openLinksInDiv(event) {
//$("#container").hide();
$("#container").load($(this).attr("href"), function () {
$("#container").show();
});
event.preventDefault();
}
});
Demo: http://jsfiddle.net/AN56C/
Or if you want all links on the page to open in that div, use:
$(document).on("click", "a", openLinksInDiv);
Noting that loading pages via Ajax won't work for any and all pages from external domains, but will work for pages from your own domain.
This whole thing seems to be the perfect case for an iframe rather than a div, in which case you could have links to external domains.
How to open javascript or jquery popup to display target url in same page
either using jquery or javascript
can anyone please provide me with a link i have searched on google but was unable to found a valuable thing
Here's some markup..
Some Site Link
<div id="popup"> This is the popup text pre $.load() </div>
Here's some code...
$('#popup').dialog({
autoOpen: false,
modal: true
});
$('a').on('click', function(e){
e.preventDefault();
$('#popup').load($(this).prop('href'), function(){
$('#popup').dialog('open');
});
});
Just use following things
<script>
$("#target").load("your link");
</script>
lets say you already make the popup appear on click of a link or a button so call a function on onClick event and pass the target url as a parameter. the in that function you can use alert like
alert(url);
and then use
window.location = url;
to redirect the page.
I have implemented highslide js and it is working fine...
Thanks fellows
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/