Adjusting window size and position using jquery (since body onload doesn't function properly in asp.net)

Currently, I am maintaining a web application built on asp.net, vb.net, and ajax. My goal is to open a new window from another page with specific height, width, and position when it loads.

Although I am aware of the window.open method, there are certain issues that prevent me from using it. Instead of setting the size using JavaScript on the parent page, I would like to set the size of the child page within the child page itself.

Initially, I considered using the body onload function on the master page. However, I encountered difficulties executing even a simple JavaScript function with this approach. Therefore, I believe utilizing jQuery would be more suitable to achieve my goal.

If anyone could provide assistance by sharing relevant code snippets, it would be greatly appreciated.

I have attempted to implement the following JavaScript code. While it works fine in a regular HTML page, it fails to execute when used on an asp.net master page.


function SetWindow(){
     var height = 400; //Set height
     var width = 400; //Set width
     var name = "winname" //Set window name
     var top = 20; //Set distance from top
     var left = 20; //Set distance from bottom
     var url = window.location.href;

     if(document.location.search=='') {
         newwin=window.open(url, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
     }
}

 <body onload="SetWindow();">
 </body>

Your assistance is sincerely appreciated.

Answer №1

give this a try

    function showWebsite() {
        window.open("http://www.example.com", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
    }

 $.ajax({
 url: "test.html",
 }).done(function() {
   showWebsite();
 });

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

What is the best way to apply CSS to an element in jQuery based on specific text content within that element?

http://jsfiddle.net/aWp2g/2/ css .highlight { color: yellow; } html <div>fox</div> <div>brown</div> jQuery if ($('div').text() == 'fox') { this.addClass('highlight'); } My code above isn& ...

What is the reason behind the failure of this ajax request?

I have encountered an issue with my ajax code. It seems to work in one file, but fails to function properly in other files. Below is the code snippet in question: $.ajax({ type: "GET", url: "get_child.php?pc_id="+pc_id.toString(), }).done(fun ...

The constant reloading of localhost is due to the connection of Mongodb with Node.js

I am facing an issue while trying to establish a connection between my Node.js Express script and the backend MongoDB 5.0.5. When I run the app.js using nodemon, it shows that the MongoDB is connected; however, on the localhost, the page keeps reloading wi ...

Manipulate SVG elements by dragging them along the boundary of the path

Looking to achieve a specific functionality where I can drag and drop an element along the edges of a drawn path, rather than inside the path itself. To clarify, the goal is to move the red marked element on the black line bordering the path, allowing move ...

Within the materia-ui table, I am facing an issue where clicking the button to expand a row results in all rows expanding. I am seeking a solution to ensure only the selected row expands

When a row is clicked, all rows in the data table expand to show inner data for each row. The issue is that clicking the expand button expands all rows rather than just the selected row. Each time I try to expand one specific row, it ends up expanding mul ...

Collapse the nested child element within when the parent container is expanded/animated downwards

I'm trying to achieve a specific effect where, when the main parent div is toggled or slides down, the child div within it should also hide. Currently, I have a parent div that toggles to display a child div. When I click on a link within the child d ...

The significance of zone.js and rxjs within the context of Angular 2

As a newcomer to Angular2, I recently learned about zone.js and rxjs. I'm curious to know if they both serve the same purpose for handling asynchronous tasks, or if each has its own specific role. Can someone explain to me the exact reasons why zone.j ...

What is the best way to send a reply from a GET request query on the server side of an express application?

Currently, I am utilizing a query to interact with a Postgres database in order to save the result into a variable within a GET request on the server-side of an Express application. Although my query successfully returns the desired issueID when executed ...

Ajax loaded scripts are unable to access global variables

Index.html <script> let bar = 1; </script> This html page is being loaded multiple times on the page using AJAX: article.html <script> if (bar === 1) { // perform a task } // Error: bar is not defined </script> Bar is a simple ...

The Outcome of Ajax Form Submission

I'm currently encountering an issue with the ShowResponse function in my Ajax Form. I am attempting to display a simple message in the #show div once the form has been submitted. The Ajax submission is functioning correctly and I am able to trigger an ...

How to utilize a PHP array within a Vue.js template

I have been exploring the realms of Laravel and vue.js recently and have encountered a challenge. Within my Laravel model, I have a PHP method that retrieves data from a database and organizes it into objects stored in an array. Now, my goal is to access t ...

Trouble submitting lengthy text in HTML form

Creating a simple HTML form <form method="post" action="process.php"> <label>First Name</label> <input type="text" name="first_name" /> <br /> <label>Last Name</label> <input type="text" nam ...

When iteratively utilizing the setValue() function, an unintentional occurrence of an 'Uncaught error' is encountered

I encountered an issue while trying to update a spreadsheet upon submitting a form. The problem is that after pressing the submit button, the remaining commands are not being executed properly. As a result, I see an error message in the console saying "U ...

The process of displaying only the month name as the title in Full Calendar

Is there a way to display the Full Calendar title with only the month name instead of "month name year name"? Here is my code attempt: $('#calendar').fullCalendar({ header: { left: 'prev', center: 'title' ...

Utilizing Python to alter the HTML source code of an external website

While examining the structure of a website (specifically Google Alerts at https://www.google.com/alerts), I entered a name and clicked on 'more options'. As I inspected the element of this page, focusing on buttons like 'How Often', I n ...

Is it possible to create a numerical unique identifier? What is the best way to resolve the issue of duplicate IDs safely?

I have a question regarding an old code that manually generates a random ID as a number, which has recently led to a duplicate ID issue. What is the most secure and effective solution to address this problem? I am considering using UUID to generate an ID, ...

Advantages of optimizing NodeJS/TypeScript application by bundling it with webpack

Currently, I am working on a Node/Express application and I am interested in incorporating the most recent technologies. This includes using TypeScript with node/Express along with webpack. I have a question: What advantages come with utilizing webpack t ...

Can a single endpoint be used to provide files to web browsers and data to REST requests simultaneously?

I recently completed a tutorial that lasted 7 hours on creating a blog, following it almost completely. The only step I skipped was setting up separate client/server hosting as suggested in the tutorial. Instead, I have a single Heroku server serving the c ...

problem with overflow in HTML and CSS opera browser

My gradient is not displaying properly in the Opera browser. Can anyone help me troubleshoot? Check out the code on jsfiddle for reference:) http://jsfiddle.net/KtDTK/7/ <div class="product_1"> <div class="product_block"> <div cla ...

What is the process for changing to a different page in NativeScript?

Having trouble creating a simple button in NativeScript labeled 'login'? I've created a login component, but when testing the code, it shows an error stating "no known component for element Login." <template> <Page> <TabV ...