I've the following code working properly which opens a pdf downoloaded in the same window:
jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
.appendTo('body').submit().remove();
I'd like open the pdf in a new tab or window.. How can I change the appendTo in order to achieve it?
Thanks in advance!!
You can set target="_blank"
jQuery('<form target="_blank" action="' + url + '" method="' + (method || 'post') + '">' + inputs + '</form>')
.appendTo('body').submit().remove();
Add target='_blank' attribute into forms.
target="_blank"
I think you can use $.ajax or $.post to get pdf url and you can use window.open() to open this url in new tab:)
Related
I have a whatsapp share button that shares the current URL (using window.location)
waCurrentPage = function() {
return encodeURI("whatsapp://send?text=Lets go here: " + 'http://' + window.location.hostname + window.location.pathname + window.location.search);
}
Button
<a class="btn btn-social-icon btn-whatsapp" href="javascript:window.location=waCurrentPage();">Whatsapp share this list</a>
I can see that from the browser side it's sending the correct URL...
...but when it gets to the whatsapp side it has cut off the second parameter
Anyone have an idea how I could fix it?
I'm trying to open a base64 PDF file in a new tab by using iframe. While opening that PDF in new tab file name is showing as data: attached my screenshot below. How can I change or set the file name?.
Note: I don't want to download the PDF I need to open in a new tab. Thanks in advance
My Code
const pdfWindow = window.open('');
pdfWindow.document.write(
"<iframe width='100%' height='100%' src='data:application/pdf;base64, " +
encodeURI(base64PDF) +
"'></iframe>",
);
Maybe this way you can use. There may have been a mistake in the arrangements.
let file = 'data:application/pdf;base64'
let prntWin = window.open();
prntWin.document.write("<html><head><title>your title in here</title></head><body>"
+ '<iframe width="100%" height="100%" src="'+ file + '" '
+ 'type="application/pdf" ></body></html>');
prntWin.document.close();
There is a way to show the filename you want, but it needs to save the base64 to LocalFileSystem.
Then the iframe load this file in LocalFileSystem.
And it needs user to grant permission once to the browser.
It works on Chrome. You can refer to below demo:
https://pdf-filename.glitch.me/
Souce:
https://glitch.com/edit/#!/pdf-filename?path=index.html%3A1%3A0
The download button fail to work...
Edit:
If you would like to use pdf.js, you can refer to:
https://daniel4wong-pdfjs-demo.glitch.me/
The title that you are refering to is in the metadata of the PDF document itself. You will need to edit the title in the document.
You can use an online editor (like https://pdfcandy.com/edit-pdf-meta.html) or any suitable PDF application.
If you are generating your PDF's on the backend you need to set the proper metadata over there.
I am working on an affiliate website for which redirect is the most critical part. I used a simple script to pop open links in a new window. But since last week suddenly chrome started blocking these popups.
$(".get-code").click(function() {
$couponId = $(this).attr("data-coupon-id");
$url = $(this).attr("data-coupon-url");
$outUrl = $(this).attr("data-out-url");
//alert("Coupon Id: " + $couponId + " URL: " + $url + " Redirect URL: " + $outUrl);
window.open($outUrl, '_self');
window.open($url, '_blank');
});
Does anyone have any idea about this?
I fixed it by breaking both the redirection into two parts.
One redirection is done on the click event and another one is using the href link of the anchor tag. This way chrome doesn't block it and also works fine in IE and Firefox.
<a rel="noopener noreferrer" onclick="return hitTarget('URL1')" href="URL2" >GRAB CODE</a>
JavaScript redirection
function hitTarget(target){
window.open(target,'_blank');
return true;
}
Here is my current code which does redirecting:
window.location.href= '/post/' + data.main_id + '/' + subject + '#post-' + data.post_id;
Code above just changes the slug when I'm in the same URL. anyway, I need to both change the slug and reload the page. How can I do that by JS or even jQuery?
You can achieve this by first appending the fragment to the URL, then reloading the page:
window.location.href += '#post-' + data.post_id;
window.location.reload();
Note however that you could improve this further by using pushState and avoiding the need to reload the page at all when the fragment changes.
You can use
location.reload();
Please, see
http://www.w3schools.com/jsref/met_loc_reload.asp
Can I create pinterest share without pin it button? I had try using these but it seem fail.
Pin it
Pin it
Is there any way I can create a pinterest share link without pin it button?
Try making your hyperlink url like this, this worked for me
string url = "http://pinterest.com/pin/create/button/" +
"?url=" + "your link" +
"&media=" + "link to youre image" +
"&description=" + "your description";
both media and description can be blank so you could do
string url = "http://pinterest.com/pin/create/button/" +
"?url=" + "" +
"&media=" + "" +
"&description=" + "";
to test it out
in my code im calling a redirect after a button press but i think this should work for you.