简体   繁体   中英

Why would a script tag run correctly if embedded in HTML, but not generated by aspx?

If I embed a special control (a prescription search box widget by rxwiki) inside a simple html file like so:

<html>
<body>
  <script type="text/javascript" id="rxwiki_sw_js" src="http://www.rxwiki.com/rune/search/widget?utm_medium=search_widget&utm_source=795f9976-4258-5fc8-A659-e5c31cccf791">
  </script>
</body>
</html>

When this page is rendered, the appropriate search control appears and operates.

However, if I embed that same element into a working aspx page it does not. Instead I just get an edit box embedded in a blank border that looks about the same size as the original image.

If I put the same code in the master page it does render, but putting it in the master page isn't an option for me.

Suggestions?

The script tries to create a like below:

<form id="rxwikiSearch" target="_blank" action="http://www.rxwiki.com/search" method="get" accept-charset="UTF-8">

When you use a masterpage, it has a form element and contents are rendered inside it. In the content if you have that script, it tries to render another form inside master page's form, which is not allowed.

I have tested with keeping a contentplaceholder at masterpage's head (which is generated by wizard) and putting the script at content page like below:

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
     <script type="text/javascript" id="rxwiki_sw_js" src="http://www.rxwiki.com/rune/search/widget?utm_medium=search_widget&utm_source=795f9976-4258-5fc8-A659-e5c31cccf791">
  </script>
</asp:Content>

And it is working fine!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM