I am trying to open links with the default ios system browser instead of the inappbroswer plugin. The following code does not open with the system browser:
function openlink(x){
window.open(x.href, "_system");
return false;
}
<h1>google</h1>
<h1>yahoo</h1>
$("html").click(function(){
$(".exLink").attr("onclick", "javascript:return openlink(this)");
});
This code does open with the system browser but it's not what I need.
<h1><a href="http://google.com" onClick='javascript:return openlink(this)'>google</a></h1>
What's the best way to get the onclick attr() to work?
Try something like this:
$(".exLink").on('click', function() { openlink(this); return false; });
It's because the click event for the .exLink is assigned, but not triggered, only when html level is clicked.
unless capturing the click event at the html level is there for a reason, try
$(function(){
$(".exLink").attr("onclick", "javascript:return openlink(this)");
})
Try simple like this -
google
Related
Need your help on this.
<A HREF=javascript:printDoc()>Link</A>
function printDoc()
{
window.print();
}
I am using a hyperlink to call a JavaScript function that prints the page. It works perfectly on Chrome, but not on Internet Explorer.
What can be the possible solution?
this kind of function calls is deprecated. Probably use
Link
Inline javascript in general should be avoided, you'd be better of with something like
Link
var link = document.getElementById('someButton');
link.addEventListener('click', function (e) {
e.preventDefault();
printDoc();
});
I've put in a call to preventDefault() there but realistically if your using a <a> tag for something that isn't a link you should consider a button or span
Helo!
I am creating a cordova app, and run in to the following issue on S4 Mini, android 4.2.2.
I have a div element
<div class="switch" id="switchOff" onclick="clicked()">
<img alt="switch off" src="img/70/switchOff.png" />
</div>
Theres no way I was able to react to a click event. I tried every possible way I know.
$('#switchOff').css('position', 'relative');
$('#switchOff').css('zIndex','10000');
var foo = document.getElementById("switchOff");
console.log('zindex: ' + $(foo).css('zIndex')); //gives it back, so it works
$('#switchOff').bind('click',function(){
alert('Bind is the winner');
});
foo.click = function(){
alert('Native click is the winner');
}
$(document).on('click','#switchOff',function(){
alert('Holaon');
});
document.getElementById("switchOff").addEventListener('click', function(){
alert('eventlistener is a winner');
}, false);
The most strange thing is that I can even change the attributes of that div, so the selector works, and its already loaded to the dom.
Another strange thing is that it works well on other devices. (motorola defy, xperia tablez-z, atrix).
I run out of ideas, can someone help with this?
where is your clicked() defined?
Did you wraped the whole code in the jquery ready listener like this?:
$(function(){
$('#switchOff').click(function(){
//do something
});
});
I have some simple code to open reddit, but i need it to open in a new window.
tried some different approaches but can't get any to work. Any idea what to add to below code?
<img src="http://www.reddit.com/static/spreddit7.gif" alt="submit to reddit" border="0" />
You obviously want to suppress the standard link behaviour by adding
return false;
to the onclick handler.
label
Consider putting that logic in a separate click handling function
function handleClick(evt) {
var url = '' // build your url here
window.open(url);
evt.target.preventDefault();
}
And add it to your link with
element.addEventListener('click', handleClick);
Try this
window.open("http://www.reddit.com/submit?url="+encodeURIComponent(window.location))
Check this link for further information
for a website, i am using the jQuery supzersized gallery script: http://buildinternet.com/project/supersized/slideshow/3.2/demo.html
As you can see in the demo, in the bottom right corner there is an little arrow button that toggles a thumbnail bar. There is no option in the config files to automatically blend this in when opening the site.
So i guess i have to simulate a click on that button (the button is the tray-button, see HTML). I tried something like this:
<script>
$(function() {
$('#tray-button').click();
});
</script>
However, this doesnt seem to work in any browsers i tested.
Any idea?
$('#tray-arrow').click(function() {
// prepare an action here, maybe say goodbye.
//
// if #tray-arrow is button or link <a href=...>
// you can allow or disallow going to the link:
// return true; // accept action
// return false; // disallow
});
$('#tray-arrow').trigger('click'); // this is a simulation of click
Try this
$("#tray-arrow").live("click", function () {
// do something
});
I assume that you want to popup the thumbnail bar #thump-tray on page load.
Here's a way to do it:
locate the file supersized.shutter.js and find this code:
// Thumbnail Tray Toggle
$(vars.tray_button).toggle(function(){
$(vars.thumb_tray).stop().animate({bottom : 0, avoidTransforms : true}, 300 );
if ($(vars.tray_arrow).attr('src')) $(vars.tray_arrow).attr("src", vars.image_path + "button-tray-down.png");
return false;
}, function() {
$(vars.thumb_tray).stop().animate({bottom : -$(vars.thumb_tray).height(), avoidTransforms : true}, 300 );
if ($(vars.tray_arrow).attr('src')) $(vars.tray_arrow).attr("src", vars.image_path + "button-tray-up.png");
return false;
});
After it, add:
$(vars.tray_button).click();
Dont forget in your page (demo.html in the plugin), to change
<script type="text/javascript" src="theme/supersized.shutter.min.js"></script>
to
<script type="text/javascript" src="theme/supersized.shutter.js"></script>
instead of using
$(function(){
//jquery magic magic
});
you culd try this witch will work your jquery magic after the full page is loaded (images etc)
$(window).load(function () {
// jquery magic
});
and to simulate a click you culd use // shuld be the same as $('#tray-arrow').click();
$('#tray-arrow').trigger('click',function(){ })
example:
$(window).load(function () {
$('#tray-arrow').trigger('click',function(){
alert('just been clicked!');
})
});
try
<script>
$(function() {
$('#tray-arrow').click();
});
</script>
Make sure that this code is after your carousel is initialized.
This looks like it's a problem of timing the trigger. The plugin also loads on document load, so maybe when you try to bind the event listener the element is not created yet.
Maybe you need to add the listener in something like the theme._init function
http://buildinternet.com/project/supersized/docs.html#theme-init
or somewhere similar.
A problem might be that your plugin detects whether the click has been initiated by a user (real mouse click), or through code (by using $('#id').click() method). If so, it's natural that you can't get any result from clicking the anchor element through code.
Check the source code of your plugin.
HI,
I am developing a web page using asp.net.
I am using some links in my web page. For that I have used some code like this.
Test
and in the ChangeLoc() method I have written __doPostBack event.
This works fine in IE7 installed in my machine. But in IE6 in another machine it does not invoke the __doPostBack event.
Edit
When I change the void(0) in href it works fine.
I would like to know whether it is a bug with IE or a JavaScript problem.
function ChangeLoc( param, arg )
{
__doPostBack ( param, arg )
}
href and onclick both get fired when you click an element, you are overwriting the onclick event with void()
change to
test
or with jQuery.
$(function(){
$("#linkId").click(function(event){
ChangeLoc();
event.preventDefault();
});
});
Do you get an error? If so, what error do you get in IE6? Can you post the code for ChangeLoc()? Also, try changing your markup to the following and see if you get the same result:
Test
Edit: removed 'javascript:' from the onclick
You can also use unobtrusive javascript syntax:
test
<script type="text/javascript">
document.getElementById("chngLink").onclick = function(e) {
if (e && e.preventDefault) {
e.preventDefault();
}
ChangeLoc('TEST','');
return false;
};
</script>
it is not good to use <a>-element for javascript functions call.
Use styled <span onclick="my_function()" class="looks_like_hyperlink">...</span>