Solution to ineffective js Code output by ashx in Chrome Kernel

Source: Internet
Author: User

Copy codeThe Code is as follows:
Public class Script
{
Public static void Alert (string message)
{
ResponseScript ("alert ('" + message + "');");
}

Public static void ResponseScript (string script)
{
HttpContext. Current. Response. Write ("<script type = \" text/javascript \ "> \ n // <! [CDATA [\ n ");
HttpContext. Current. Response. Write (script );
HttpContext. Current. Response. Write ("\ n //]> \ n </script> \ n ");
}
}

In form. ashx, call:

Copy codeThe Code is as follows:
Script. AlertAndGoBack ("Note: There are duplicate users! ");

The result is no longer effective in the new version 360 of 6.0, but the output is

Copy codeThe Code is as follows:
<Script type = "text/javascript">
// <! [CDATA [
Alert ('note: There are duplicate users! ');
Window. history. back ();

//]>
</Script>

But it is completely normal in IE.

Later, it was found that Google's Chrome kernel was called in the speed mode of the 360 browser, so this code does not work in the Chrome browser.

Solution:

Copy codeThe Code is as follows:
// Set:
Context. Response. ContentType = "text/plain ";

// Change:
Context. Response. ContentType = "text/html ";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.