Is there a way to open a link in a new window without using the _blank attribute?

I am facing an issue where I have a webpage with a URL linking to a PHP file that displays an image, and I want to open this picture in a new window without the blank page showing up.

Currently, when I click on the URL using the code below, a new window opens along with a blank page, which is not desired as I have to close it every time. I only want the window to display the picture.

window.open('image.PNG', 'image', 'toolbar,menubar,scrollbars,resizable,height=800,width=400,left=600,top=400');

Any suggestions on how to achieve this?

//edit Using prevent default does not seem to work when I have

<a href="file.php">Link</a> //URL to PHP with script above

Answer №1

Copy and paste the following code snippet into your browser's console:

open('image.png');

If a new tab opens displaying the desired image, try the next set of instructions:

<a href = 'image.png' id = 'image'>

and

document.getElementById('image').onclick = funciton(e){
    e.preventDefault();
    open('image.PNG', 'image', 'toolbar,menubar,scrollbars,resizable,height=800,width=400,left=600,top=400');
};

If this method does not work as expected, try the alternative option by executing the code below in your console:

open('file.php');

A new tab should open with the desired image. Proceed to try the following:

<a href = 'file.php' id = 'file'>

and

document.getElementById('file').onclick = funciton(e){
    e.preventDefault();
    open('file.php', 'image', 'toolbar,menubar,scrollbars,resizable,height=800,width=400,left=600,top=400');
};

If all else fails, please leave a comment below for further assistance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determining the largest range possible in a sorted array of integers

I need help with a JavaScript implementation for the following challenge. Imagine we have a sorted array: [1,2,5,9,10,12,20,21,22,23,24,26,27] I want to find the length of the longest consecutive range that increments by 1 without duplicates. In the ...

Ways to execute a script from termly on NextJS using JSX

I've been utilizing termly to assist in creating legal terms for a website I'm developing. They provided me with some HTML containing a script, but I am struggling to get it to execute on a page in JSX. I attempted to use both Script and dangerou ...

Learn how to launch a new webpage using jQuery Colorbox plugin

I am experiencing an issue with jQuery colorbox on my website. Instead of opening web pages in a dialog, they are opening as regular links. Despite searching for demos, I have not found any that work correctly. Below is the code I am using: <asp:GridV ...

Capable of displaying array in console, however unable to iterate through its elements

Encountering an issue while working with React and fetching data from a JSON API. Initially, everything was functioning smoothly until it came to displaying the data. Strangely, I could see the data being logged in the console. Here is what the console lo ...

Using Jquery to retrieve data from PHP for validation in a datepicker widget

I am currently working on a project where I need to retrieve an array of invalid dates from a PHP file and highlight them in red on the date picker. However, the code below is not correctly populating the unavailableDates array as expected. It seems to d ...

Import failures in Three.js could be attributed to potential issues with Webpack

Please note: I am utilizing create-react-app along with three.js v0.99.0. In my current project, I am faced with the challenge of importing specific modules from three.js to avoid bundling the entire library, which results in a large uncompressed file siz ...

changing the action URL of a jQuery form dynamically upon submission

I am currently utilizing a jquery ajax form library and I would like to alter the action URL when submitting the form. Here is the HTML code: <div class="modal-body form"><?php echo form_open_multipart("#",array('id'=>'mng_form ...

Is there a permanent solution to fixing the error code -4094 that is repeatedly occurring during React Native startup?

When attempting to execute react-native start, an error occurred which has not been encountered before. The error message is as follows: ERROR ENCOUNTERED Loading dependency graph...events.js:287 throw er; // Unhandled 'error' event ...

Leveraging Javascript within MVC3, either on a master page or child page

I'm currently developing a web application utilizing MVC3 and I am curious about the best practices for incorporating JavaScript. Specifically, I am uncertain about whether to include JavaScript in the master page as well as in individual child pages. ...

choose a value from a dropdown menu to reset other dropdowns to their default values

I am encountering an issue with my PHP form that consists of 7 dropdown lists. Whenever I select a value from one of the dropdown lists, I want the other 6 to reset to their default values if they were previously opened. I believe using JavaScript is neces ...

Fetching an image from Firebase Storage for integration into a Vue application

I am encountering an issue while trying to fetch an image from my firebase storage to display it in my Vue application. The upload process from the app to firebase storage runs smoothly, but there is an error during retrieval. My setup involves using the F ...

Utilize Vue to localize the click events of buttons on the webpage

I have a scenario where I have several buttons on a page, and when I click one to toggle its text, all of the buttons change. How can I utilize VUE to isolate functionality and make each button's @click event only affect the clicked button? In the cod ...

Update the browser URL dynamically without redirecting the page, by utilizing JavaScript after an AJAX call receives a

I am currently endeavoring to find a solution to replace the URL on my page without triggering a reload. My approach involves utilizing an infinite scroll JavaScript plugin. Upon receiving a response from an AJAX call, I intend to update the URL with the n ...

How to search for a value in Firebase database and save it to an HTML table?

I am working on fetching specific values from my 'snapshot' and storing them if they exist. Below is the snippet of my code: function paydata(){ firebase.database().ref("pay/0/0/").once('value', function(snapshot){ var resp ...

The Process of Developing Applications

As a newcomer to web development, I have a solid understanding of HTML and CSS, and am learning JavaScript. When considering creating a web app, would it be better for me to focus on writing the functionality in JavaScript first before integrating it int ...

Dynamically include a new prop to the final element within an array of React components

I have been searching everywhere for a solution to this problem, but I can't seem to find one as I am unable to edit the props object. Here's what we are currently doing. We have a menu with subsections and we achieve this by: const firstSectio ...

What is the method for replacing "left" with the label of an element?

Here is my code snippet: <label><li><input name="skills[]" class="skills" value="1" type="checkbox" /></li>a</label> <label><li><input name="skills[]" class="skills" value="2" type="checkbox" /></li>b& ...

Contrast 2 GET objects retrieved from separate controllers

I have 2 collections of data from different controllers. Data Collection 1 (Controller Name): [{id:1,"name":"jakov"},...] Data Collection 2 (Controller Nickname): [{id:1, "nickname" : "jandric", "nameId" :1, "title" : "master"},...] I send data from C ...

Verify whether a variable is empty or not, within the sequence flows in Camunda Modeler

When working with a sequenceFlow in a process instance, I need to check a condition that may involve a variable that has not been defined yet. I want the flow to proceed even if the variable is not defined, rather than throwing an ActivitiException. I hav ...

Ensure that the CSS element pseudo-class does not override the styling of its child

Looking to style an anchor element that contains other HTML elements. Here is the basic code structure: HTML: <div class="container" id="sub-menu"> <div class="row" data-bind="foreach: subMenu"> ...