Have you noticed the interesting parameter list for the window.open() object?
Is there a possibility to use window.open({options..}); instead?
What are your thoughts on this matter?
Have you noticed the interesting parameter list for the window.open() object?
Is there a possibility to use window.open({options..}); instead?
What are your thoughts on this matter?
One way to include options is by passing them as a URL parameter:
const newURL = myURL + "/?options=" + JSON.stringify(options);
window.open(newURL);
The language does not come with a built-in facility for this feature.
However, creating one yourself is quite simple.
Here's an example:
function createPopup(url, name, options) {
if (arguments.length === 2) {
options = name;
name = options.name;
}
var features = false;
for (var key in options) {
if (!options.hasOwnProperty(key)) continue;
if (key === "name") continue;
if(features)
features += ",";
features += key + "=";
if (!options[key])
features += "no";
else if (options[key] === true)
features += "yes";
else
features += options[key];
}
return window.open(url, name, features);
}
oh, well
function createNewWindow(attributes) {
var options = [], attributesList = ['height', 'width', 'scrollable', /* list of all possible attributes */];
for (var j = 0; j < attributesList.length; ++j) {
if (attributesList[j] in attributes)
opts.push(attributesList[j] + '=' + attributes[attributesList[j]]);
}
return window.open(attributes.url, attributes.name, options.join(','));
}
Not quite. The function you're thinking of is a built-in JavaScript method for accessing the Document Object Model (DOM).
It's worth noting that the use of an 'options object' gained popularity with the rise of JSON, even though the DOM specification existed long before.
If you need help creating a window opener utility, consider constructing a JavaScript object with parameter fields and customizing its toString() method.
Sorry, there is no pre-existing wrapper available. However, creating your own should be relatively simple.
It's unlikely since the features are specified as a comma-separated list of window features
Source: MDC
var WindowObjectReference = window.open(strUrl,
strWindowName
[, strWindowFeatures]);
You could create a function that takes an object as input and then invokes window.open()
with the proper parameters
Have you considered creating a personalized function to decode a JSON object and then trigger the window.open() method with customized parameters generated from the decoding process?
It seems like this is not available. To make it compatible with parameters, we can easily convert it from json to the required format. Here's a quick one-liner using global regular expressions:
JSON.stringify(properties).replace(/true/g, "yes").replace(/false/g, "no").replace(/:/g, '=').replace(/} |{ |"/g, '');
This method works on most browsers, including Internet Explorer 11.
A more modern alternative is to use replaceAll:
JSON.stringify(properties).replaceAll("true", "yes").replaceAll("false", "no").replaceAll(':', '=').replaceAll(/} |{ |"/g, '');
Although this approach has limited browser support, it achieves the same outcome.
I am trying to display a table with items from JSON data. I have created a Service that returns the JSON data. In my controller, I am querying the Service to receive an array of data. It's a little confusing because I am putting the response in a new ...
I have modified some code I found in a tutorial on creating hoverable dropdowns from W3. Instead of the default behavior where clicking on a link takes you to another page, I want to pass a value to a function when a user clicks. Below is a snippet of the ...
I am having an issue with updating a form that contains multiple radio buttons based on data retrieved from an API. The challenge is that only the last set of radio buttons displays the value correctly. Below is the code snippet I am using (angular bracket ...
After implementing a basic HTML code to add a background image to my webpage, I noticed there is still some empty space at the top of the page. I attempted to adjust the position of the background image using the following code, but it only lifted it upwar ...
I have a JavaScript-based application with three key files: index.html app.js input.json The app.js file references input.json multiple times to populate content in div elements within index.html. My goal is to enhance the functionality so that when acc ...
I have a large table filled with numerous items that require individual images to be added. Let's take a look at the code snippet below. <tr><td><img src=".jpg" width=100 height=100/></td></tr> Although I could manually ...
Here's the data I received: { 0:{modifierId: 4, modifierName: 'Garlic', modifierPrice: 60 } 1:{modifierId: 1, modifierName: 'Tartar ', modifierPrice: 60} 2:{modifierId: 3, modifierName: 'Herb ', modifierPrice: 60} item ...
Update I have included actual code below, in addition to the concept provided earlier. Here is the async array access structure I am trying to implement: for (p = 0; p < myList.length ; p++){ for (k = 0; k < RequestList.length; k++){ i ...
I have two Nodejs applications, one for the front-end and the other for the back-end. The back-end app is secured with token access using express-jwt and jsonwebtoken middlewares. My issue is as follows: when I make a request from the front-end to the bac ...
Having some trouble formatting data pulled from my database and encoded into JSON using json_encode. I want to make it more readable in my android app by changing the format. Here is an example of the current encoded string at the bottom. Any suggestions w ...
Welcome to My Index defined("DS") || define("DS", DIRECTORY_SEPARATOR); defined("ROOT_PATH") || define("ROOT_PATH", realpath(dirname(__FILE__))); require_once(ROOT_PATH.DS.'classes'.DS.'Helper.php'); $page = 'default'; $ur ...
I am currently working with a simple sankey chart in Highcharts. Everything is functioning correctly with the sample data I have implemented, except for one issue - when I increase the font size of the data labels, not all the data is displayed. The info ...
I'm currently experiencing an issue with my HTML page that involves calling two JS files for two different image sliders on the same website page. One slider works perfectly fine while the other does not. I'm confused as to whether it's perm ...
Currently, I am working on developing a CRUD (Create, Read, Update, Delete) App using Express and LowDB. So far, I have successfully implemented the create and read functions, but I am facing issues with the delete function. This is an example of what th ...
Is there a way to retrieve JSON data containing the names of top albums, artist names, and IDs from iTunes into PHP? https://itunes.apple.com/us/rss/topalbums/limit=10/json I attempted the following: <?php $content=file_get_contents("https://itunes.a ...
I am currently facing a challenge in creating an Angular directive as I am unable to pass the necessary parameters for displaying it. The directive code looks like this: (function () { "use strict"; angular.module("customDirectives", []) .directive ...
I'm looking to integrate a Microsoft Login Button into a Next Js application using Material UI. However, after adding the necessary package from NPM and refreshing the page, I encountered the error mentioned above. When I tried setting ClientId="a973 ...
Apologies if this question has been asked multiple times, but I have a specific JSON issue that I need help with. My JSON data consists of an array list of notifications, and within the 'extra' object, there is a 'contract' object. Howe ...
I'm currently implementing a recursive directive called https://github.com/dotJEM/angular-tree to iterate through a model structure like the one below: $scope.model = [ { label: 'parent1', children: [{ ...
I have successfully integrated draggable functionality for table columns using jQuery Sortable within my Laravel application. I am now facing the challenge of updating the database with the data from these columns through AJAX. Despite researching online ...