How do I open PDF on a new tab, target="_blank" alone does not work it still open the pdf in the same tab.
Method-1 : HTML
<a target="_blank" href="http://your_url_here.html">Link</a>
You can simply do that with setting target="_blank" for an example check this
More Details
Method-2 : Javascript
<a onclick="openInNewTab('Your URL');">Something To Click On</a>
function openInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
Without your code is hard to tell what's wrong but did a fast test and this worked for me..
<a target="_BLANK" href="pdf/your_pdf.pdf">YOUR PDF</a>
You have to know: "_Blank" is not working as a "new tab" on every browser.
To do that, you have to use js like this:
Lnk
(it will work on any browser, "_blank" will not)
EDIT: Of course, here the "link" in window.open will be the path to where your PDF file is stored.
EDIT2 (thanks to vlaz): Yep, it will work on any browser if JS is enabled, if he his not it will not.
Related
Hello my Wonderful Developers, I need help on this
Let say my website is https://nkiri.pw/ and I want to click on a button or Link, I want my current page to be replace by this page https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3 and my present page should open another page automatically. How can I achieve this successfully ?
I was able to solve it by doing this:
<a role="button" id='mike' href="<?php echo "https://".$_SERVER['SERVER_NAME']."/" ?>" target="_blank" class="btn btn-primary">Primary</a>
<script>let linkElement = document.getElementById("mike"); linkElement.addEventListener("click", openNew);function openNew() {window.open("https://itinerarycarter.com/h9xdx19n?key=2053deb616c8b3ac8566b44a8ec7c092", "_self");}</script>
You are using a hyperlink. So you have a href="" in your html tag. You can also set the target (where the page should be opened) to _blank. This means, that the page will be opened in another tab. So if you write it like this:
href="https://nkiri.pw/" target="_blank"
It will open your current page in another tab. Then you can open the new page with js.
let linkElement = Document.getElementById("yourIdOfTheLinkElement");
linkElement.addEventListener(function() {
window.open("https://itinerarycarter.com/qm37kgvszd?key=7f255a06003c7158485ad05f1e9672f3", "_self");
});
How can I open a file(pdf or image) in a new tab in BLAZOR?
I tried using:
await JSRuntime.InvokeVoidAsync("open", new object[2] { path, "_blank" });
using a javascript function with window.open();
In Both cases I got: This localhost page can’t be found. What should I do?
Check proper extension of the image or URL path is correct.
You can follow the below example:
$(document).ready(function(){
$('img.image').click(function(){
window.open($(this)[0].src, '_blank')
});
});
Two options I can suggest:
Via a button.
#inject IJSRuntime jsRuntime
<button #onclick="#LoadPage">Load Page</button>
#code {
async Task LoadPage()
{
await jsRuntime.InvokeAsync<object>("open", "MyPage", "_blank");
}
}
Via a link.
<a class="dropdown-item" href="MyPage" target="_blank">
where the razor page you want to launch has the following at the top:
#page "/MyPage"
If you would like to open a tab you can use this.
HTML:
You will need to fill in the href for where you want to go.
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
I need to open my app in new window by this link:
<a onclick="window.open('http://somesite1.com/', '_target', 'width=510,height=413,resizable=yes,scrollbars=yes').focus();">Link</a>
After opening the application handles events like:
$registerSubmitButton.on("click", function() {
var newWindow = window.open("https://somesite2.com", "_blank");
newWindow.opener.close();
return false;
});
But this click event doesn't work only in Safari.
Why?
I am not sure but if you cheat a little bit may this will work. I don't have a safari browser so just a try for you.
<a id="openWindow" onclick="window.open('http://somesite1.com/', '_target', 'width=510,height=413,resizable=yes,scrollbars=yes').focus();">Link</a>
<a id="fakeOpenWindow" style="display: none;" href="https://somesite2.com" target="_blank">
$('#openWindow').click(function(){
$('#fakeOpenWindow').click();
});
Hi all i am writing a Rails application and i include some link_to_remote links
The generated code is
Test
That works perfectly fine on Safari and Firefox but when i try to click the link on IE7 and Opera it does not even hit the server.
Any hints ?
Use a fully qualified URL: http://.....
This is a bad practice to include all of this code in the <a href> tag anyways. I suggest you make a function such as:
function doAjax(url)
{
new Ajax.Request(url, {asynchronous:true, evalScripts:true});
return false;
}
in the javascript code. And change the url to say instead:
<a href="#" onclick="return doAjax('/b10/categories/games?category=Action');">
Test</a>