A HREF URL won't work - javascript

I am trying to get the following link to work.
<a href='#' onclick='window.open(" | &ESPP_Info_URL | ");return false;'>Employee Stock Purchase Plan Information</a>
Basically the &ESPP_Info_URL variable takes in a url so that the code below looks like...
<a onclick="window.open(https://...);return false;" href="#">Employee Stock Purchase Plan Information</a>
But when I click the url it just refreshes the page. Does anyone know how to get this to access the link within the window.open function?

Try this, You need wrap url with in single quotes ' - window.open('YOUR URL HERE')
<a onclick="window.open('YOUR URL HERE');return false;" href="#">Employee Stock Purchase Plan Information</a>

Here's an extended version with more dynamic functionality, jic:
http://jsfiddle.net/ofnh7gke/
And the smaller version:
http://jsfiddle.net/rqf3s72n/
Javascript
var sites = ['http://www.google.com','http://www.github.com'];
document.getElementById('btnStockPurchasePlan').onclick = function(){
window.open(sites[0],'_parent');
return false;
};
HTML
Employee Stock Purchase Plan Information

Related

Javascript Bookmarklet Duplicating URI / URL

I have the following bookmarklet:
javascript:findlink=document.getElementsByClassName(%22download_link%22)[2].href;window.open('https://myfiledrive.com/users/files/add?url='+findlink,'_blank');void(0);
Example:
<a class="download_link" href="example.com/pdf1.pdf">
<a class="download_link" href="example.com/pdf2.pdf">
<a class="download_link" href="example.com/pdf3.pdf">
Basically, it searches the currently active page, for the third iteration of an tag with the class "download_link", and stores it in the variable "findink",
Then it loads 'https://myfiledrive.com/users/files/add?url='+findlink
In the above example it should load:
https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf
but what ends up happening is that this gets loaded:
https://myfiledrive.com/users/files/add?url=example.com/pdf3.pdf?url=example.com/pdf3.pdf
so basically it's duplicating url=
What am I doing wrong? Thanks.
The url param shouldn't be duplicated. You're not appending to findlink or anything. You can try the snippet below, it's exactly as you've posted.
Chrome will block the popup, but if you read the error message, there's no duplication going on:
Blocked opening 'https://myfiledrive.com/users/files/add?url=https://stacksnippets.net/example.com/pdf3.pdf' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.
url is only in there once no matter how many times I click.
<a class="download_link" href="example.com/pdf1.pdf">1</a>
<a class="download_link" href="example.com/pdf2.pdf">2</a>
<a class="download_link" href="example.com/pdf3.pdf">3</a>
download

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
}

Passing parameter to #Url.Action based on jquery hasClass output

I am trying to pass an integer parameter to Url.Action based on hasClass output of jquery. something like below but is invalid syntax.
<li class="myClass">
<a href="#Url.Action("SetActionMode", "Home", new { enable = $(this).find('i').hasClass("fa-check") ? 0 : 1 })">
<i class="fa fa-check"></i> Debug Mode
</a>
</li>
What is the correct syntax for above or is there some easy way to do this?
I'd say you should 'interrupt' link clicking, construct URL and then go to this URL.
$(".myClass a").click(function(event) {
event.preventDefault();
var url = $(this).attr('href');
// here you do whatever makes sense
url = url + "?enable=" + ($(this).find('i').hasClass("fa-check") ? 0 : 1)
window.location.href = url;
});
ASP.NET needs a value from jQuery, however the two don't run at the same time - jQuery is run on the client side, ASP.NET is run on the server side. So, on the server side, it compiles and sends it to the client side, then, on the client side, it runs the jQuery code. The hasClass is jQuery code, the new { ... is ASP.NET code, this is why it's incorrect syntax.
You cannot do it like this,But you have another option i.e GIve your anchor tag a class, then write a click function for this, After this use location.href to perform the same:
<li class="myClass">
<a href="javascript:void(0)" class="clickme">
<i class="fa fa-check"></i> Debug Mode
</a>
</li>
<script>
$('.clickme').on('click',function(){
location.href='/Home/SetActionMode?enable='+$(this).find('i').hasClass('fa-check')?0:1;
})
</script>
This will Surely do what you need.

Facebook share with javascript

I am using html javascript to share a link on facebook.
I am using this code:
<a href="javascript:"onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=test.com');" target="_blank">
Share on Facebook
Now i want to replace test.com with the current url link in the browser .
How to do it !
You can use window.location or window.location.href which provides the current URL. In your example, you can use something like the following:
<a href="javascript:" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location);" target="_blank">
For more information see Window.location on Mozilla.org which has the following description:
The Window.location read-only property returns a Location object with information about the current location of the document.
Though Window.location is a read-only Location object, you can also assign a DOMString to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com' is a synonym of location.href = 'http://www.example.com'.
I believe it should work if you use window.location.href, so your code would be the following:
<a href="javascript:"onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location.href);" target="_blank">
window.location.href will get the current url e.g.
window.open('https://www.facebook.com/sharer/sharer.php?u=' + window.location.href);

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/ ;)

Categories