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.
My attempt to execute a PUT call on my Web API involves configuring the WebApiConfig.cs file to send data back to my Web project in camel case format. config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesCont ...
Is there a way to access the parent scope from a partial using #each in Handlebars? Main template: (out of each = {{index}})<br> {{#each someItem}} (in each, but not on partial = {{../index}}) {{>part}} {{/each}} Partial: <div class="part ...
Can someone guide me on how to properly test mutations and state? I have a modal window component that is rendered when the showModal property in the state is true. There is an event triggering a mutation that changes this property. How can I verify that a ...
I have a function in my codebase that is responsible for loading HTML templates asynchronously: loadTemplate: function(url) { return new Promise(function(resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open("GET" ...
Currently, I am in the process of building a library using TSDX, which is a powerful CLI tool for package development based on Rollup. My project involves a collection of country flags SVGs that need to be imported and displayed dynamically when required. ...
I'm currently working on a sample demo that involves the use of PHP and AJAX to read a JSON file. In my JavaScript code, I have: // main entry point function init(){ var button = document.getElementById("button"); button.addEventListener("clic ...
I'm trying to retrieve Google search results using the Google Ajax API and then display them in a DIV element. Google presents its results in JSON format, but unfortunately, I am unsure how to handle it. I have searched extensively but have not foun ...
I have a query regarding npm and its functionality. I also posted the same question on Reddit, but haven't received a satisfying answer yet. Let's use the jQuery npm package as a case study. Upon running the command npm install jquery, I notic ...
Take a look at this array and its corresponding expected output: In Javascript, is it possible to dynamically determine how many levels there are in the array ary? var ary = ["a","b",["c","d"],"e",["f","g",["h","i"],"j"]]; Output: 3 var ary = ["a","b",[" ...
I'm currently working on a feature that requires users to click on two different points and calculate the distance between them. However, it seems like the clicks are occurring at random positions, resulting in inaccurate calculations. The calculati ...
I am currently working on my new portfolio site and I have a question about how to place handlebars expressions inside an #each loop. The project is an express application generated by express-generator, and I am using the express-handlebars NPM package: ...
Currently in my Node.js project, I am attempting to write records to a DynamoDB table using the batchWriteItem() method. When I call the insertTransactionDetails() function for the first time, I send 9 records to be inserted. On the second call to the sam ...
Is there a way to achieve serialization without triggering the submit function for an ajax call? I've searched extensively for a solution to this issue without any luck. The java script function is invoked when a button within the form is clicked. do ...
When an AJAX request is made, it typically appears in the network tab in Chrome. However, if a client-based redirect occurs at the same time, the AJAX request may be cancelled. But does this mean that the request still reaches the server and executes as ...
While searching around, I stumbled upon this HTML 5 code snippet: window.history.pushState("object or string", "Title", "/new-url"); I started thinking: how can this be implemented? Is there a way to utilize this code to change the URL to without needin ...
While working with mongodb and nodejs to search for data within an embedded document, I encountered a strange issue. The query functions as expected in the database but not when implemented in the actual nodejs code. Below is the structure of my data obje ...
I find it fascinating that I can use this constant even before declaring it. The code below is functioning perfectly: import { relations } from 'drizzle-orm' import { index, integer, pgTable, serial, uniqueIndex, varchar } from 'drizzle-orm ...
I am currently developing a Vue/Vuetify application that showcases a large number of images (10-20k) in a grid view along with some additional information. These images are grouped into different sections, and clicking on an image opens an overlay displayi ...
Currently, I am following a MEAN stack tutorial on Thinkster and encountering an issue with my Angular factory service. Angular.js:11598 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [] H ...
In my ASP.NET MVC application, I am struggling to post the updated value from a CKEditor in a textarea. Here is the code snippet: <textarea name="Description" id="Description" rows="10" cols="80"> This is my textarea to be replaced with CKEditor ...