disappearing the link in a window.open popup

I have a situation where I am opening a window with the code window.open("mytest.aspx");. The issue arises when the user closes that pop-up window - I need to have the link on the parent page hidden. In essence, how can I hide the anchor link on the parent page from the pop-up that was opened using window.open()?

Thank you for your assistance.

Answer №1

Check out this JavaScript code for triggering a popup window when clicking on a link:

function ShowPopup()
{
  document.getElementById("popupLink").style.visibility='hidden';
  window.open("mypage.html");
}

Answer №2

Check out this related post for more information - Best practices for handling popup closing

In the original post, the recommended approach involves using the setInterval function to continuously check the status of the popup. Once it has been closed, you can then trigger your 'hide anchor' functionality.

I hope this explanation proves helpful!

Answer №3

I may have misunderstood the initial question. Here is an alternative approach:

function DisplayPopup(){
  main_Window = this;
  window.open('example.html');  
}

Create another function within the main window:

function removeLink(){
  $("#linkID").hide()
}

Before opening the popup, execute the following code:

main_Window.removeLink();

I regret any confusion caused by my previous response.

Answer №4

If you want to hide a link when the window is closed, you can use the onunload event. In this case, 'hr1' refers to your link id on the opener page:

Here's how you can do it on the popped-up page:

function CloseOpener(){ 
window.opener.document.getElementById('hr1').style.display='none'; 
} 

Then, add this code to the same popped-up page:

<body onunload="CloseOpener();"> </body>

Alternatively, you can use a separate button on the same page to trigger the closing:

 <input id="Button1" type="button" value="button" onclick="CloseOpener();"/>

This setup has been tested and confirmed working on my browsers, but there are some considerations to keep in mind when using the onunload event. For more information, check out this discussion: onunload not working in Chrome and Safari.

Answer №5

Here's a solution you could experiment with:

let newWindow = window.open('mytest.aspx');
newWindow.onbeforeunload = function(){ 
   document.getElementById("theLink").style.visibility='hidden';   
}

Keep in mind, this method works best when the popup page and parent page are within the same domain.

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

You can easily dismiss the modal by clicking on any part of the screen, not just the button

I have a problem with my current code where I can only close a modal by clicking on a specific button. I want to modify it so that the modal can be closed by clicking anywhere on the screen. Unfortunately, as a JavaScript beginner, integrating new code sni ...

Load Angular modules dynamically

Is there a way to dynamically load a module (js, css and html) using a single directive at any point during the app's lifecycle? <my-module id="contacts"></my-module> The template for this directive looks like this <my-module id="con ...

NodeJS Error: Attempting to access 'json' property from an undefined source

I'm in the process of setting up a CronJob to make an API call and save the response into the database: const CronJob = require("cron").CronJob; const btc_price_ticker = require("../../controllers/BtcExchange/Ticker"); const currency = require("../.. ...

Unable to Retrieve Modified Content with $().text();

In the process of developing an app, I am encountering a challenge where I need to transfer user input to another element after processing it. However, I am facing an issue with accessing the updated value of the <textarea> using .text(), as it only ...

How can I import an excel spreadsheet using Javascript, or alternatively, convert an excel file to a text document

I have been updating my file upload page to handle both text and excel files. However, when trying to read excel files with my current code, I am getting strange output. It seems that my function, which was originally designed for text files, needs modific ...

Mudblazor - Tap or click within the designated area to trigger the drag and drop functionality

I have incorporated the Mudblazor CSS framework into my Blazor WebAssembly project. Within the drag and drop zone, I have included a button that is supposed to remove each uploaded image. However, when I click on the remove button, it only opens up the fi ...

Prevent the transmission of keydown events from dat.GUI to the Three.js scene to maintain event isolation

This code snippet (below) contains 2 event listeners: renderer.domElement.addEventListener("pointerdown", changeColor, false); document.addEventListener("keydown", changeColor, false); Both of these event listeners trigger a color chan ...

Issues with the functionality of the jQuery notify plugin are being encountered when used in a

I am currently utilizing the jQuery notify plugin and have included all the necessary JS files in the header. However, whenever I attempt to call the $.notify function in another JS file that also involves AJAX, I encounter difficulty accessing the $.notif ...

Calculating the total of an array's values using JavaScript

Receiving information from an API and looking to aggregate the values it contains. Consider the following code snippet: function totalPesos(){ $http.get('/api/valueForTest') .then(function(data){ $scope.resumePesos = data.data.Re ...

Is it not possible to utilize Eval within a LinkButton?

Currently residing within a Repeater element. Here is the code for a LinkButton I am working on: <asp:LinkButton ID="AggiungiSocial" CssClass="<%# ((Eval("UniqueID").ToString() != SocialEngine.paginaCrushsite.ToString()) ? "dashboard-check ...

Exploring Angular's Dependency Injection

How can I verify that a module has properly loaded its required dependencies? I've added ngAnimate to the module definition, but it doesn't appear to be functioning within the application when it runs. The environment I'm navigating is quite ...

Is it possible to pass an HTML element's id attribute to a function in JavaScript?

In the following code snippet, I am looking to send the id=content to the function mr and then display the result in the passed id=result. While this functionality is currently limited to this HTML file, I aim to extend it to other HTML pages by adding the ...

Issues arise when trying to use Prettier and ESlint in conjunction with one another

It appears that prettier is not formatting the code as desired. Here is my current ESLint configuration: "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ &q ...

Steps for extracting values from a data-bound listbox's selected items and then parsing them into different textboxes using JSON

I am relatively new to programming in general, so please try to explain things in a simple way as I may not fully understand. English is also not my native language. My objective is to populate several textboxes with different values obtained from a json ...

Azure experiencing issue with MUI Datepicker where selected date is shifted by one day

I have developed a unique custom date selection component that utilizes Material UI and Formik. This component passes the selected date value to a parent form component in the following manner: import React from 'react'; import { useField } from ...

Could a PHP script running over Apache outperform a standalone C# program executing the same counting algorithm?

When it comes to PHP scripts on Apache, they are optimized for multiple users accessing them simultaneously. So the question is, will 1000 requests arriving at approximately the same time be processed faster than a C# .Net program running the algorithm 10 ...

Guide to scraping a website using node.js, ASP, and AJAX

I am currently facing an issue where I need to perform web scraping on this specific webpage form. This webpage is dedicated to vehicle technical reviews, and you can try inputting the car license CDSR70 for testing purposes. As mentioned earlier, I am u ...

Save documents in Firebase storage

Currently in the process of developing a web application using Firebase and Angularjs as my frontend tools. Curious to know whether it's feasible to store various file types within the Firebase DB. Could you shed some light on any potential limitatio ...

Having trouble with Javascript in getting one-page scroll navigation to work?

Hey there, I am working on creating a one-page scroll navigation with some basic javascript to add a smooth animation effect that takes 1 second as it scrolls to the desired section. However, I seem to be experiencing an issue where it's not functioni ...

Integrate new functionality into the plugin's JavaScript code without directly editing the JS file

I need to incorporate a new function called 'setInputDataId' at the same level as the existing function '_select' in the plugin js file without directly modifying the file itself. I am seeking guidance on how to add this new function. ...