 |
Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

March 21st, 2010, 10:47 AM
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
How to appear Html tags in .aspx page when run it
Code:
document.write("<html><body> msman88 </body></html>");
The above code is in default.aspx page, and I need to import it in a javascript as an external file as below,
Code:
<script type="text/javascript" src="http://localhost:49718/uu1/Default2.aspx"></script>
But when I run the page default.aspx, I get follows only:
Code:
document.write("msman88");
the problem I wnat to solve is to to make html tags displayed on the page when running it, and the page should display code exactly like the 1st code above, and do not want html tags to be executed by browser..
Hint:
1) Previously, I used to use HtmlEncode() in c#, but problem I faced that the output is not a valid javascript code.
2) Now I shifted to make the code is static on an aspx page, but the problem is still facing us here, that html tags are also executed by the browser when running the page.
After that I solved it by putting the html tags inside <xmp> tag as follows:
<xmp>
Code:
<xmp>document.write("<html><body> msman88 </body></html>");</xmp>
That made the output is containing html tags and they are not executed by browser, but I still I face the same problem, the <xmp> made the output is not a valid javascript.
__________________
ASP.NET & C#
Last edited by msman88; March 22nd, 2010 at 05:19 PM..
|

March 21st, 2010, 11:22 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Didn't we do this here: Problem with "HttpUtility.HtmlEncode()"
Anyway, again, you're not proving enough information. What's the purpose of this code / exercise? What other content does Default2 contain? Does it just output this code or does it output an entire page? Where exactly did you place the link / script tag to Default2.aspx? And what's the point of document writing am <html> element when you are already inside an <html> element with a <script> child element?
And finally, it's not clear what the actual problem is. What do you mean with:
Quote:
But when I run the page default.aspx, I get follows only:
Code:
document.write("msman88");
|
That doesn't make a whole lot of sense. HTML elements don't get stripped from source code automatically, so I am pretty sure the tags are still there, but you just don't see them. Explain us how you run this page, what you input where, and what output you see and where and we may be able to help you.
And didn't the previous thread put you in the right direction?
Imar
|

March 21st, 2010, 11:51 AM
|
Friend of Wrox
|
|
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
|
|
For that file you tried to import, it should be coded as a javascript file, not a aspx file. Hope this clean things up and make it easier for you. Something like the following:
Code:
<html>
<head>
<script type="text/javascript" src="apple.js"></script>
</head>
<body onload="apple();">
</body>
</html>
Here is what's in apple. js:
Code:
function apple() {
alert("apple");
}
Based on what we talked in last thread, I guess maybe you have the need to make your javascript slightly different from time to time based on certain conditions. maybe that's why you used aspx to generate it. Actually to do that, there is still no need to dynamically generate the . js file, what you can do is:
1) Make your javascript functions taking parameters; (make it 100% static content)
2) In your calling web page, pass in the parameters. (this one has dynamic content any way, to pass parameter to js should not be a big deal)
Hope this helps.
Last edited by PeterPeiGuo; March 21st, 2010 at 12:02 PM..
|

March 21st, 2010, 02:38 PM
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
I found it, see
Code:
<xmp>document.write("<html><body> msman88 </body></html>");</xmp>
But a problem what I have, that code became is not valid a javascript more.
so what's still needed?
__________________
ASP.NET & C#
|

March 22nd, 2010, 02:57 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What about an answer to the many questions I asked? There are many ways to do what you're doing, but you need to know the scenario in order to pick the right solution.
Just posting a snippet of code with a "But a problem what I have, that code became is not valid a javascript more." is not enough. You need to *explain* what you're trying to accomplish.
Cheers,
Imar
|

March 22nd, 2010, 03:44 PM
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
what should I add more on the code to make it is a valid javascript more ?
__________________
ASP.NET & C#
|

March 22nd, 2010, 03:46 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Why do you refuse to answer the questions that need to be answered in order to answer yours?
Imar
|

March 22nd, 2010, 05:20 PM
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Imar
Why do you refuse to answer the questions that need to be answered in order to answer yours?
Imar
|
i edited the original topic. you can understand well now.
__________________
ASP.NET & C#
|

March 22nd, 2010, 05:26 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I don't.
I still don't know what code the page outputs, how it does it, what other code it contains (e.g. whether it clears the response and only emits JavaScript or the JavaScript is mixed with the rest of the page). I don't uderstand the final purpose of all this, and I don't know exactly what you want to accomplish.
Why do you only post tiny snippets of your code without explaining how things fit together and where you call what? tell us how things are related to each other. And so on and so forth.
So, by all means, play hide and seek and make this as hard as you want. But if you want help, be clear, concise,and describe what it is that you want as detailed as possible.
Cheers
Imar
|

March 22nd, 2010, 05:36 PM
|
Authorized User
|
|
Join Date: Feb 2008
Posts: 89
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
I got tired, and any thing is clear.
please try this out:
1)
create an html page, and include following in it:
Code:
<html><body><xmp>document.write("<hmtl><body> msman88 </body></hmtl>");<xmp></body></hmtl>
I need <xmp>, but it made the code is not a javascript any more, when calling the page inside a javascript code.
so what is to make it a valid javascript code and with existence of <xmp>
cheers!
__________________
ASP.NET & C#
|
|
 |