How to open a link new tab with print command? - html

I have a hyperlink with contains third party website link. I want to open this link in new tab with print command. How can i do this?
Suppose:
Print
Note: I know how to open a link in new TAB/Window. I want to know how to open with PRINT DIALOG.

You could try something like this:
​​​​​​​​​​​​​​​​​print pdf

This method works well for me.
<a href="/url/" onclick="window.open(this.href).print(); return false">

There is no way for a website to cause a browser to load a third party website and display the print dialog for it automatically.

<img src="print.png" style="cursor:hand" onclick="window.frames['pact'].print();"><iframe name="pact" src="pact.pdf" width="0" height="0" frameborder="0"></iframe>

This absolutely worked for me. I'm coding a site in Angular 6.
Print
Here's my source (enter link description here) but watch out for double quotes in the originak source.
:)

This is depend on your browsers, you can enable the tab for new link, If you are using Firefox you can enable the tab using Firefox -> Options -> options -> open a new windows in a new tab instead option

Related

Share a link via URL scheme to Telegram

I want to share a link via URL scheme for Telegram.
I have created this:
tg://msg?text = www.example.com?t=12
The link, opens telegram but nothing else happens.
I have used the same code for Viber, and it works:
viber://forward?text = www.example.com?t=12
And it opens a new message in Viber with this text:
www.example.com
In the other words, it cuts my URL.
Any ideas?
You can also use telegram.me share link which falls back to webogram if a telegram app is not installed on the device.
https://telegram.me/share/url?url=<URL>&text=<TEXT>
This works with me:
tg://msg?text=Mi_mensaje&to=+1555999
You have the following options for a URL...
https://t.me/share/url?url={url}&text={text}
https://telegram.me/share/url?url={url}&text={text}
tg://msg_url?url={url}&text={text}
In case you want to confirm, here is the official API source: Core.Telegram.org: Widgets -> Sharing Button.
If you are interested in watching a project that keeps track of these URLs, then check us out!: https://github.com/bradvin/social-share-urls#telegramme
You can use the link telegram.me which will provide a preview page with an alert requesting to open the link in the application.
https://telegram.me/share/url?url=<URL>&text=<TEXT>
The second option is calling the application link directly:
tg://msg_url?url=<url>&text=<encoded-text>
I particularly prefer the second option, which also works on desktop applications.
For Telegram share:
Objective C:
if([UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tg://msg?text=test"]){
[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tg://msg?text=test"]
}else{
//App not installed.
}
Swift 3.0:
let urlString = "tg://msg?text=test"
let tgUrl = URL.init(string:urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!)
if UIApplication.shared.canOpenURL(tgUrl!)
{
UIApplication.shared.openURL(tgUrl!)
}else
{
//App not installed.
}
If you have used canOpenURL, then need to add in info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tg</string>
</array>
PHP
Link
JavaScript
<script>TEXT="any text or url";</script>
<a onclick="window.location='tg://msg?text='+encodeURIComponent(TEXT);">Link</a>
Telegram
with this we can open xdg of telegram and if we select contact , by default sending text will come in message field.
Maybe you use localhost therefore it does not show share. try it in live host
To check if the Telegram is installed you can do the following (borrowed from the Whatsapp sharer module of ShareKit):
BOOL isTelegramInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tg://msg?text=test"]];
iOS checks if there's any app installed which can handle the tg:// scheme, which is Telegram.
Try using tg://share:
Link
Just tested, this way it works both opening telegram app or browser in case it's not installed:
let webURL = NSURL(string: "https://t.me/<YOUR ID>")!
UIApplication.shared.open(webURL as URL)
Your have two problems:
On one hand you are using the wrong scheme for sharing URLs, the correct one is msg_url;
On the other hand you are trying to share a URL with parameters. You need to encode your ? in order to make it work. The percent code is %3F
Extra Tip: Also if you want it to be a link once shared you should include the HTTPS:// encoded of course.
Try this and you'll see it works fine: tg://msg_url?url=https%3A%2F%2Fwww.example.com%3Ft=12
If you want to open chat with bot or people, just write this simple code
<a href="https://t.me/targetedusername">
You should stop using the protocol for the desktop applications because it does not work on the evolving web: it does not work on Web apps, ChromeOS, or some mobile devices.
Always use the NEW way: https://t.me because it will open the Telegram DESKTOP app in Windows\Linux\Mac IF THE USER WANTS\HAS it, otherwise it will open the WEB page\web app which is THE WAY.
https://web.telegram.org/k
https://web.telegram.org/z
Telegram has TWO web apps that have been building out for the past year!
Both are great, adding TONs of parity, and have different approaches.

How can I open multiple links using a single anchor tag

So here's a simple but interesting question, how can I open multiple links using single <a> element?
Using this only opens the first href
Click Here
You can certainly try this
Demo
Click Here
I searched for that but unfortunately all methods I found don’t work.
I have one way to that with JS (but one linkwill open in the current tab):
HTML Code:
<a id="myId">go</a>
JS Code:
myId.onclick = function(){
open('https://www.example1.com');
location.href = ('https://www.example2.com');
}
So here it will open example1.com in another tab.
Then in the current tab, will open example2.com
Note: The order of JS Lines is required otherwise it will not work.

Force navigator to Open Link in New Tab by URL

i have a request if possible,
i have an interface which containts a table :
name of application url
XXXXXX www.xxx.com
Problem is when I click in the url I lose my information on my current page.
my question is there is a code language by Internet explorer FF chrome... provide this action
open in tab this url to put in the url like the method version and the other
like this about:version ==> open in new tab : this url to put in the url navigator
and we get a new tab
thank you for help .
i try open in a new tab by tools provided by IE , but if possible provide a solution like a code entered in url to open a new tab
If I get you, you want your link to open the page in another tab.
You may use the target attribute of the link like this :
<a href="somepage.html" target=newtab>text</a>
If you want something you can type in the URL field of the browser, that is a bookmarklet, you may use this :
javascript: window.open('http://www.dystroy.org');
In most browsers, ctrl-click a link do the same thing.
EDIT :
If what you can modify is only the href attribute of the link, you can make this href be like this :
<a href="javascript:window.open('http://www.dystroy.org');" target=_blank>text</a>
If its a hyperlink just add a "target" to the hyperlink with its value as "_blank". Working example:
<a id="termsLink" href="www.someLink.com" target=_blank>
Terms and Conditions</a>
The java script solution works great in case of shortcodes which offer you an href (or url) option but no target parameter. Here is an example with a popular callout shortcode:
[callout title='Your big Title' text='your small text...' button_text='CLICK ME' button link="**javascript:window.open**('http://www.dystroy.org');"]
Without the javascript, the linked page would open onto the current one.
You don't need any code to open a link in a new tab or window. HTML already has that functionality built in.
Use an tag to show your url and use the target attribute to tell it to open in a new window.
Example:
www.xxx.com
Learn more about a tag and target attribute here

HTML / Javascript One Click Print (no dialogs)

Is it possible to have a print option that bypasses the print dialog?
I am working on a closed system and would like to be able to pre-define the print dialog settings; and process the print as soon as I click the button.
From what I am reading, the way to do this varies for each browser. For example, IE would use ActiveX. Chrome / Firefox would require extensions. Based on this, it appears I'll have to write an application in C++ that can handle parameters passed by the browser to auto print with proper formatting (for labels). Then i'll have to rewrite it as an extension for Chrome / Firefox. End result being that users on our closed system will have to download / install these features depending on which browser they use.
I'm hoping there is another way to go about this, but this task most likely violates browser security issues.
I ended up implementing a custom application that works very similar to the Nexus Mod Manager. I wrote a C# application that registers a custom Application URI Scheme. Here's how it works:
User clicks "Print" on the website.
Website links user to "CustomURL://Print/{ID}
Application is launched by windows via the custom uri scheme.
Application communicates with the pre-configured server to confirm the print request and in my case get the actual print command.
The application then uses the C# RawPrinterHelper class to send commands directly to the printer.
This approach required an initial download from the user, and a single security prompt from windows when launching the application the first time. I also implemented some Javascript magic to make it detect whether the print job was handled or not. If it wasn't it asks them to download the application.
I know this is a late reply, but here's a solution I'm using. I have only used this with IE, and have not tested it with any other browser.
This Sub Print blow effectively replaces the default print function.
<script language='VBScript'>
Sub Print()
OLECMDID_PRINT = 6
OLECMDEXECOPT_DONTPROMPTUSER = 2
OLECMDEXECOPT_PROMPTUSER = 1
call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
End Sub
document.write "<object ID='WB' WIDTH=0 HEIGHT=0 CLASSID='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>
Then use Javascript's window.print(); ties to a hyperlink or a button to execute the print command.
If you want to automatically print when the page loads, then put the code below near tag.
<script type="text/javascript">
window.onload=function(){self.print();}
</script>
I am writing this answer for firefox browser.
Open File > Page Setup
Make all the headers and footers blank
Set the margins to 0 (zero)
In the address bar of Firefox, type about:config
Search for print.always_print_silent and double click it
Change it from false to true
This lets you skip the Print pop up box that comes up, as well as skipping the step where you have to click OK, automatically printing the right sized slip.
If print.always_print_silent does not come up
Right click on a blank area of the preference window
Select new > Boolean
Enter "print.always_print_silent" as the name (without quotes)
Click OK
Select true for the value
You may also want to check what is listed for print.print_printer
You may have to choose Generic/Text Only (or whatever your receipt printer might be named)
The general answer is: NO you cannot do this in the general case but there some cases where you might do it.
Check
http://justtalkaboutweb.com/2008/05/09/javascript-print-bypass-printer-dialog-in-ie-and-firefox/
If you where allowed to do such a thing anyway, it would be a security issue since a malware script could silently sent printing jobs to visitor's printer.
I found a awesome plugin by Firefox which solve this issue. try seamless printing plugin of firefox which will print something from a web application without showing a print dialog.
Open Firefox
Search addon name seamless printing and install it
After successful installation the printing window will get bypassed when user wants to print anything.
I was able to solve the problem with this library: html2pdf.js (https://github.com/eKoopmans/html2pdf.js)
Considering that you have access to it, you could do something like that (taken from the github repository):
var element = document.getElementById('element-to-print');
html2pdf(element);

href to asd#zxc.txt (filename contains number sign) with target="_blank" for IE

What I need to put in href for targetting to asd#zxc.txt,
tried:
asd#zxc.txt
but IE opens new window with "asd" in URL,
this one works fine:
asd#zxc.txt
but I need to open file in new window
Thx
UPD:
also tried with JS
window.open("asd%23zxc.txt","_blank") IE opens new window with "asd" only
you should seriously consider changing your filename. honestly, i've never seen anyone use a # in a filename.
Firefox doesn't work with this either. It opens a new tab with the # in the URL but says that asd doesn't exist.
the only way i can see this working is if you had a PHP script serve the file. something like getfile.php?file=asd#zxc.txt.
even then, you might have to encode the # sign before sending the request to your script (i've never sent a # through POST or GET). also, make sure that you set proper access restrictions on a script like that.