How can I retrieve the URL of the parent page from an iframe and save it in an input field

Hello, I'm having trouble accessing the parent page of an iframe using JavaScript. I've tried different methods but haven't found a solution that works well for me.

I have one HTML page and another page with a form and buttons. I need the form on the second page (external_form.aspx) to access the parent page, retrieve the URL, and store it in my input tag.

    <label for="first_name"><%=GetPhrase("FORMFIELD_FIRSTNAME")%>:</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br/>

    <label for="last_name"><%=GetPhrase("FORMFIELD_LASTNAME")%>:</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br/>

    <label for="email"><%=GetPhrase("FORMFIELD_EMAIL")%>:</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br/>

    <label for="phone"><%=GetPhrase("FORMFIELD_PHONE")%>:</label><input  id="phone" maxlength="40" name="phone" size="20" type="text" /><br>

    <label for="description"><%=GetPhrase("FORMFIELD_DESCRIPTION_INSIDE")%>:</label><textarea name="description"></textarea><br/>

    <input type="hidden"  id="00Nb0000001Vrag" name="00Nb0000001Vrag" size="20" type="text" value='<%=MyCookies.Tracker() %>' />

    <!--UserIP-->
    <input type="hidden"  id="00Nb0000002EPku" maxlength="20" name="00Nb0000002EPku" size="20" type="text" value='<%Response.Write(Request.ServerVariables("remote_addr"))%>'  /><br>

    <textarea style="display:none;" id="00Nb0000001Vraq" name="00Nb0000001Vraq" rows="10" type="text" wrap="soft"><%=Request.ServerVariables("HTTP_REFERER") %></textarea>

    <!--Referral URL-->
    <textarea style="display:none;"  id="00Nb0000002EPl3" name="00Nb0000002EPl3" rows="5" type="text" wrap="soft"><%=Request.ServerVariables("HTTP_REFERER") %></textarea><br>
    <label for="ParentPage">ParentPage</label><input id="parentpage" name="ParentPage" type="text" value=""  /><br />


    <input type="submit" name="submit"   class="button" value='<%=GetPhrase("FORMFIELD_SEND")%>' />
  </asp:Panel>
</form>

Answer №1

Take a look at this specific query for my answer.

The key is to attach the relevant information (such as the parent page title) to the source URL of the iframe and extract it from the embedded page. This method is the most effective way to achieve the desired outcome.

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

Search for a specific folder and retrieve its file path

Is there a way for me to include an export button on my webpage that will allow users to save a file directly to their computer? How can I prompt the user to choose where they want to save the file? The button should open an explore/browse window so the ...

Merge two JSON objects together by matching their keys and maintaining the original values

After having two separate JSON objects representing data, I found myself in the position of needing to merge them into one combined result. The initial objects were as follows: passObject = { 'Topic One' : 4, 'Topic Two' : 10, &apos ...

Executing a service prior to the loading of Angular 7 applications or components

Currently, I am in the process of developing an application using Angular 7. So far, everything is running smoothly as I have successfully managed API calls, JWT Token authentication with C#, and updating LocalStorage when needed during user login and logo ...

Incorporate an image into your webpage with the Fetch API by specifying the image link - JavaScript

I've been attempting to retrieve an image using the imageLink provided by the backend server. fetchImage(imageLink) { let result; const url = `https://company.com/internal/document/download?ID=${imageLink}`; const proxyurl = 'https:/ ...

Deleting an element in an Array of objects using Typescript

export class AppComponent implements OnInit { title = 'bucketList'; bucketList: BucketListItem[] = [ new BucketListItem( "Goa Trip", "Travel to Goa" ) ]; ngOnInit() { } onItemAdded(eventData) ...

How to designate a default selection value using local array data source in Select2.js version 4.0?

If I am using the select2.js v4 plugin with a local array data source, how can I set the default selected value? For instance, consider the following code: var data_names = [{ id: 0, text: "Henri", }, { id: 1, text: "John", }, { id: 2, text: ...

I'm having trouble with my script only fetching the first row of my PHP table. Can someone please take a look at my code

Below is my JavaScript snippet: $('input#name-submit').on('click', function() { var name = $('input#name-submit').val(); if($.trim(name) != ''){ $.post('getmodalreasonUT.php', {name: name}, ...

How can I disable a checkbox in AngularJS?

Is there a way to automatically disable a checkbox when selecting an item from the combo box? For example, if "ABONE" is selected, Angular should disable the ABONE checkbox. Note (for example): DefinitionType: ABONE https://i.sstatic.net/vcZpR.png ...

Utilizing the datepicker options function within a different function

I'm working on a function that utilizes a promise to retrieve data from an asynchronous ajax call: $("#mySelect").on('change', function() { var mySelectValue = $('#mySelect').val(); var promise = getAvailableDates(mySe ...

A guide on adjusting a function to pause execution until a line is complete

In the code snippet below, there is an angularJS function named myFunc: $scope.myFunc = () => { myModule.getConfig().update(params); myModule.go(); myModule.log('ok'); }; Additionally, there is a go function defi ...

The issue with the `.load` function in jQuery not functioning properly

I'm currently tackling an issue with a project where I am encountering difficulties with the .load function not working in Google Chrome. Below is the JavaScript code: function link1() { $('#loadarea').html('loading.....' ...

ASP.NET "Data" Error: Trouble Parsing JSON Data on the Front-End

I am currently facing an issue with the configurations on my asmx page. The code is set up like this: using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Script.Serialization; using Syst ...

Storing a date in MySQL using Vue.js and Node.js

My current tech stack consists of nodejs and express.js for the backend, vuejs for the frontend, and mysql as the database. I am facing an issue where I cannot send a date retrieved from localStorage to my mysql database. Whenever I try to send the date, ...

Discovering pairs of numbers that are not next to each other in an array that has not been

When working with an array of unsorted numbers, the goal is to identify and extract pairs of elements that are not consecutive. Input [2,3,4,5,9,8,10,13] Desired output (2,5)(8,10)(13,13) To achieve this: Input = [2,3,4,5,9,8,10,13] If we arrange the num ...

Styling for older versions of Internet Explorer (IE10 and earlier)

Could it be true that IE 10, 9, and others no longer support conditional statements? Is it also accurate to say that JQuery does not support the browser object above version 1.9? I am facing an issue with CSS rendering differently in Chrome and IE. A Goog ...

Is there a way to determine the number of clicks on something?

I'm attempting to track the number of times a click event occurs. What is the best method to achieve this? There are two elements present on the page and I need to monitor clicks on both of them. The pseudo-code I have in mind looks something like ...

Is it possible for using str_replace('<') to protect against code injected by users?

Recently, I've been working on a script that involves user input. In this script, I use echo str_replace('<', '&lt;', str_replace('&','&amp;',$_POST['input']));. It seemed like a solid f ...

What are the steps to send AJAX data before closing the page?

Trying for over 7 hours to send a value to the database when the user closes the page, like online and offline. Still struggling to find a working solution. <script tysssspe="text/javascript"> //ST window.onbeforeunload = function(){ var user_st = ...

How come my Ajax call is setting the 'Content-Type' to 'application/x-www-form-urlencoded' instead of 'JSON' as specified in the dataType parameter?

I have encountered an issue while responding to a button click using the code snippet below. The console.log() confirms that the function is being called, but the HTTP request it generates contains the header "Content-Type: application/x-www-form-urlencode ...

What is the best way to transmit information using the POST method in JavaScript?

When using javascript, the typical way to redirect a page with a parameter is the following: window.location = "add-new-cos.jsp?id="+id; However, the id value is sent to the next page using the GET method. I am interested in sending it using the POST met ...