How to click on an image with a hyperlink using Javascript? - javascript

The HTML of the page I wish to use for this is as follows:
<A HREF= "http://www.example.com"
TARGET="_new" status="Home Directory" title="Home Directory"
urn="Home Directory" FOLDER="http://www.example.com"><IMG align=textTop border="0" src="images/buttons/mywork.gif" alt="Select this icon to show your Home Folder" ></td>
How can I simulate a click on this hyperlinked image just using Javascript? I don't have edit privileges for this page so I need to work with what I have already got in the page (above)

You can use firebug plugin for firefox and code your javascript from the console. Google chrome also has a console.

Give it an id for a start and then invoke using "apply"
var x = document.getElementById("linky");
x.onclick.apply(x);

I would use the jQuerify plug-in. Then type $('a').click(); in the Firebug console.

Related

How to make a contact's phone number clickable to call and to send a message in ionic?

I cloned the ionic project from GitHub
While the contact's phone number is not clickable to call and message. So for the index.html file line 39, I converted from
<p ng-if="contact.emails.length > 0">{{contact.emails[0].type}} : {{contact.emails[0].value}}</p>
to
<p ng-if="contact.phones.length > 0">{{contact.phones[0].type}} : <a ng-href='{{contact.phones[0].value}}'>{{contact.phones[0].value}}</a></p>
But it turns out the app will not load any contact's information anymore.
Is there anything I missed or am I totally wrong on sending data?
to make phone call with ionic you need to add this code in confi.xml
<access launch-external="yes" origin="tel:*" />
and in your view you need to add:
<a ng-href=tel:{{user.phoneNumber}} class="button button-positive">Call me</a>
Update:
I've just noticed it's (probably) an issue with loading data not the link itself. Would need to see your controller code to know more about why it's not populating the ng-href if it's not the issue below...
Previously:
Using the following href should be enough to trigger a call:
tel:' + number
Angular (which ionic sits on) doesn't like anything unusual going into an anchors href unless you tell it you want it to. See here:
http://forum.ionicframework.com/t/ng-href-tel-redirecting-to-call-with-empty-number/4567/2
The quickest fix, if you 'just' want it to work is this in your view:
<p ng-if="contact.phones.length > 0">{{contact.phones[0].type}} : {{contact.phones[0].value}}</p>
and then in your controller:
$scope.triggerCall = function(number){
document.location.href = 'tel:' + number
}

How to open a URL link from JavaScript inside a Google Apps Script HTML Google Site Gadget

I have written an HTML (not UI) gadget in Google Apps Script to be embedded in a Google Site. The gadget presents a drop-down with options that contain URL/display name value/text pairs.
I want to put a button in the gadget that opens a new window corresponding to the selected URL. But, basically, I get an "Object does not contain an 'open' method" error when I execute
window.open(url);
Is there a way around this? I can (and have) created gadgets with anchor tags that successfully open other windows, but doing this same action from javascript appears to not be allowed.
Anything that accomplishes the functionality is fine. A jQuery-based solution would be great.
Thanks.
Due to Caja’s sanitization, all the javascript functions are not supported that's why can't open a new window in App Script.
The workaround to display a popup in App Script is to use an overlay window(which is not a popup technically but appears like a popup) like jQuery modal dialog which are supported in App Script.
http://jqueryui.com/dialog/#modal-form
However iframe tags are not supported in App Script, so an attempt to open a url in modal window with the help of iframe tags will not work.
You can read more about these restriction in App Script from the link below :
https://developers.google.com/apps-script/guides/html/restrictions**
Hope it helps!
You can open the link directly by running the window.open() JS in a dialog using the HTMLService.
Here's a demo sheet (take a copy to see the script).
openNewWindow() is assigned to the button.
Code.gs:
function openNewWindow() {
var htmlString =
'<div>' +
'<input type="button" value="Close" onclick="google.script.host.close()" />' +
'</div>' +
'<script>window.open("http://www.google.com")</script>';
var htmlOutput = HtmlService
.createHtmlOutput(htmlString)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setHeight(60);
SpreadsheetApp
.getUi()
.showModalDialog(htmlOutput, 'Opening New Window...');
}
It's not possible to do that because of caja sanitization. The options bellow will not work.
1) jquery - $("#some_link_id").click()
2) javascript - window.open, window.href, etc...
The only workaround but I guess that will not fit to your problem is creating links with target="_blank" to open new windows but as I said is not possible to click in these links though javascript/jquery.
My Link
I was able to achieve this using a form. On submit, set the action of the form to the desired URL, as determined by the selected item in the select box.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$('document').ready(function(){
$('#yourForm').attr('onsubmit',null); //set onsubmit to Null for NATIVE Caja sandboxmode
$('#yourForm').submit(function(){
var val = $('#yourSelect').val(); //get value of select box
$('#yourForm').attr('action',val); //set action of form
});
});
</script>
<div>
<select id="yourSelect">
<option value="https://www.google.com">Google</option>
<option value="https://www.bing.com">Bing</option>
</select>
<form id="yourForm" method="get" target="_blank" action="">
<input type="submit" value="Open Selected">
</form>
</div>

Scrapy parsing of the hidden information appearing after link click

I try to parse some hidden information:
<a id="showInfoBtn" rel="nofollow" title="SomeTitle" href="some_link/some_hash"
onclick="return showInfo(event)">Info showed here after click</a>
When I manually click to this link, only get request to http://www.google-analytics.com appears at the firebug. And page not reloaded - only info showed as a link text.
How can I get info by scrapy?
I did not understand very well if what you're trying to get is to show some info inside the a tag or in other part of the page. But in any of the cases that will also depend on what does the showInfo() function return.
If the first case is what you need and showInfo() returns the text with the info, i believe this is what you're looking for:
<a id="showInfoBtn" rel="nofollow" title="SomeTitle" href="#" onclick="this.innerHTML=showInfo(event)">
Info showed here after click
</a>
Here's a demo with the example http://jsfiddle.net/P49Dv/ ;)

SharePoint Javascript Popup Link inside MasterPage

In SharePoint I am trying to create a link that pops up a window
<a id="Z5" href="javascript:popUp('<% $SPUrl:~site/Pages/Mine.aspx%>')" runat="server" style="text-decoration:none;color:#000000">Mine</a>
But when I use that code i get a link with exactly javascript:popUp('<% $SPUrl:~site/Pages/Mine.aspx%>)' in my page how can I use the SPUrl and still have a javascript popup any ideas?
I ended up switched my link to
<a id="Z5" href="javascript:popUp()" runat="server" style="text-decoration:none;color:#000000">Mine</a>
Then changed my JS to
window.open("<asp:Literal runat="server" Text="<%$SPUrl:~site/pages/Mine.aspx%>" />"
and it worked.

Javascript code working in IE but not working in Firefox?

I have this code :
<a href="javascript:document.forms['form1'].student_pic.click()">
<img src="images/mypic.png" alt="" width="161" height="29" border="0" style="margin-top:10px" />
</a>
<input style="display:none" type="file" name="student_pic" id="student_pic" />
This code is working successfully in IE but it's not working in FF.
off course there is form on my page called form1
When the user click the image, select file window will let the user select image and put it in hidden file element.
What is the proplem?
Thanks
Your problem is simply that .click() to open the file chooser dialog does not work on all browsers. I'm not aware of any workaround.
Common way around is have the file input in place but with opacity of 0 which actually means it's hidden, and over it place your custom image or text. Make sure the "browse" button is exactly where your text/image is and it will work - clicking the custom text/image will actually click the browse buttton.
I have such code somewhere so if you won't be able to achieve this I'll search for that code.
Not supported in Gecko yet:
Gecko 2.0 note(Firefox 4)
Starting in Gecko 2.0 , calling the click() method on an <input> element of
type file opens the file picker and lets the user select files.
from https://developer.mozilla.org/en/HTML/Element/input#File_inputs

Categories