Javascript Bookmarklet Duplicating URI / URL - javascript

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

Related

HTML: How to make page keep on the "href" page, and open a new page for "onclick"

I tried to fix hard code(web link in href) in the following line:
'<a class="top_a" target="_blank" href="http://10.74.55.99:3000/"><img src="images/load.svg"><img src="images/nbsp.png">LoadServer</a>'
modified to:
<script type="text/javascript">
function openLoadserver() {
window.location.href = load_server; //defined load_server in other file
}
</script>
'<a class="top_a" target="_blank" href="#" onclick="openLoadserver()"><img src="images/load.svg"><img src="images/nbsp.png">LoadServer</a>'
The result is, after I click "LoadServer", current page will open the load server page, and a new tab page open the "current page" again.
My expected result is current page is keeping as original, new tab page will open the load server.
What should I do?
<a class="top_a" onclick="openLoadserver()"><img src="images/load.svg"><img src="images/nbsp.png">LoadServer</a>
Notice the difference, the target attribute :) You don't need href either

Can't open external link in dropbox hosted website

I have a single html page hosted in my Public Dropbox folder.
The page loads and all works well except when I try to navigate a new page to an external website.
The url is supposed to go to "www.paypal.me/cloud9cincy/"
But when the page loads, it goes to "https://dl.dropboxusercontent.com/u/33811101/www.paypal.me/cloud9cincy/"
I cannot figure out how to make this work.
function paypal(){
var test = $('#paypal').attr("href");
window.open(test, '_blank');
}
<button id="paypal" onClick="paypal();">Donate to Cloud9:Cincy</button>
Presumably you have something like this:
<a id="paypal" href="www.paypal.me/cloud9cincy/">paypal link</a>
That is being interpreted as a relative URL. You should instead specify it absolutely like:
<a id="paypal" href="https://www.paypal.me/cloud9cincy/">paypal link</a>

my page always redirects me to my server

I'm trying to make a redirection to other page (for example google) but it doesn't work. This is the code:
function algo(a) {
$.get("links/privado/verlink.php?" + a, function(data, status) {
document.getElementById("algunacosa").href = data;
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="algunacosa">Ir al link</a>
<button onclick="algo">Retrive link</button>
if the response is: http://google.com it redirects me to http://mrvikxd.ddns.net/m/http://google.com and appears an 403 error
Edit: I've seen the code on the Google Chrome development console and the href of <a id="algunacosa"> is href="http://google.com". I don't know why it doesn't go to Google.
Using the rel attribute on your anchor tag, you should be able to force the link to lead to an external site. https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types
<a id="algunacosa" rel="external">Ir al link</a>
Just fixed. verlink.php was in UTF-8 BOM and it was producing the \uffef character what is not visible but enought to confuse the browser

Attribute href doesn't work in backbone

I've this html code in my template:
<a class="icon icon-home pull-right" href="index.html"></a>
If I click on it, nothing happens and no redirect to index.html is done. If I substitute href value with another (for example "#/friend") it is correctly written in the URL and caught by router. I don't understand the reason. The current URL I'm into when I try this is:
file:///C:/Users/Stefano/workspace/SocialGossip/assets/www/index.html#/back

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