Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:24:14+00:00 2026-06-18T05:24:14+00:00

we have the following situation: in default.aspx we have a link: <a href=javascript:doPost()>test</a>. and

  • 0

we have the following situation:

in default.aspx we have a link:

<a href="javascript:doPost()">test</a>.

and the JS code:

function doPost() {
    $.post('AnHttpHandlerPage.aspx',"{some_data:...}", function(data) {
        if(data.indexOf("http://")==0)
            window.open(data);
        else{
            var win=window.open();
            with(win.document) {
                open();
                write(data); //-> how to execute this HTML code? The code also includes references to other js files.
                close();
            }  
        }
    }).error(function(msg){document.write(msg.responseText);});
}

The callback can first be an url address or 2nd html code that must be executed.
Option 1 fits, but in option 2, a new window will be opened where the code has been written but not executed.

It’s clear, since it happens in the stream, it can’t be executed. So the question, how can you fix it? Maybe a refresh(), or similar?

Because of the requirement of the customer, the workflow can not be changed, so it must be solved within doPost().

EDIT

The response in case 2 is HTML like this. This part should be executed:

<HTML><HEAD>
<SCRIPT type=text/javascript src="http://code.jquery.com/jquery-latest.js">
</SCRIPT>
<SCRIPT type=text/javascript>                      
$(document).ready(function() {
do_something... 
});                          
</SCRIPT>
</HEAD>
<BODY>
<FORM>...</FORM>
</BODY>
</HTML>

Please help. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:24:15+00:00Added an answer on June 18, 2026 at 5:24 am

    In your JS code it should be something like this:

    function doPost() {
        $.post('AnHttpHandlerPage.aspx',"{some_data:...}", function(data) {
            //if(data.indexOf("http://")==0)
                  if (data.type!="url")   //i will add a data type to my returned json so i can differentiate if its url or html to show on page.
                window.open(); // I dont know why this is there. You should
            else{
                var win=window.open(data.url); //This data.url should spit out the whole page you want in new window. If its external it would be fine. if its internal maybe you can have an Action on one of your controllers that spit it with head body js css etc.
            /*  with(win.document) {
                    open();
                    write(data); //-> how to execute this HTML code? The code also includes references to other js files.
                    close(); */ // No need to write data to new window when its all html to be rendered by browser. Why is this a requirement.
                }  
            }
        }).error(function(msg){document.write(msg.responseText);});
    }
    

    The overall logic is this

    1. You do your ajax call on doPost
    2. Find out if data returned is of type url or anything that need to open in new window
    3. If it is url type it would have a url (check if this is not null or empty or even a valid url) then open a new window with that url. Have a read of W3C window.open for parameters
    4. If you want to open and close it for some reason just do that by keeping the window handle but you can do this on dom ready event of that new window otherwise you might end up closing it before its dom is completely loaded. (someone else might have better way)
    5. If its not url type then you do your usual stuff on this page.

    If this does not make sense lets discuss.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following situation: function Mach3Code(Str: String): String; var StrOut: String; begin StrOut
i have the following situation : with my function i get an XML file
I have the following situation: I have a person with default fields like: Name,
I have a question regarding the jquery/javascript: I'm in the following situation: I have
I have the following script element in my web page: <script src=default.js type=text/javascript></script> Using
I have following situation - Have a MongoService class, which reads host, port, database
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11
I have following situation: String a = A Web crawler is a computer program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.