Dreamweaver can generate the attached codes in JavaScript so that users can record the last updated date in a webpage.
The instruction works fine inside DW but it was skipped by most browsers as comments.
Placing the codes inside the "< script language = javascript > ... < /script >" markup does not help.
Anoter unsuccessful thing that I have tried is just to strip off the comment signs. It seems the syntax/format is not correct.
Pls help.
<!-- #BeginDate format:It1 -->14-10-2021<!-- #EndDate -->
Related
I have a simple search engine on one of our older websites. This site is running IIS 6.0 on Windows Server 2003. The search functionality is provided by Microsoft Indexing Service.
You can see the search functionality on our website. (Just type in "speakers" and you will see some hits.
I would like to use the "FullHit" feature offered by the indexing service. When using this feature the Indexing service inserts the full hit results in between "begindetail" and "enddetail" on a target web page.
The problem that I have is that the documents that are being returned have HTML. This looks messy. (Just click on "Hit Locator Tool" in the search results above to see what I mean.)
I would like to create a DIV section such as ...
<DIV name="target">
begindetail
enddetail
</DIV>
Then, after the page is populated I would like to use javascript to strip out all of the HTML elements (but not the data) between the opening and closing DIV.
For example, <FONT color="magenta">Good Data</FONT> would be modified to only show Good Data.
I can also use Classic ASP if necessary.
Please let me know if you have any suggestions or know of any functions that I can add to the target page to accomplish this task.
Thanks in advance.
I inspected your webpage, and there definitely must be some logic errors in your ASP code. (1) Instead of something like <div></div> being passed to the browser, it is HTML entities for special characters, so it is being passed like <DIV> </DIV>, which is very ugly and is why it is rendering as text instead of HTML code. In your ASP code, you must not be parsing the search result text before passing it to the browser. (2) All of this improperly-formatted code is inserted after the first closing html tag, and then there are closing body and html tags after the improperly-formatted code, so somewhere in your ASP code, you are telling it to append the code to the end of the document, rather than insert it inside the original <body></body>.
If you want to decode the mixture of HTML entities, <br> tags, and text into rendered HTML, this JavaScript may work:
window.onload = function() {
var text = decodeHTMLEntities(document.body.innerText);
document.write(text);
}
function decodeHTMLEntities(text) {
var entities = [
['amp', '&'],
['apos', '\''],
['#x27', '\''],
['#x2F', '/'],
['#39', '\''],
['#47', '/'],
['lt', '<'],
['gt', '>'],
['nbsp', ' '],
['quot', '"']
];
for (var i = 0, max = entities.length; i < max; ++i)
text = text.replace(new RegExp('&'+entities[i][0]+';', 'g'), entities[i][1]);
return text;
}
jsFiddle: https://jsfiddle.net/6ohc1tkr/
But first things first, you need to fix your ASP code, or whatever you use to parse and then display the search results. That's what is causing the improper formatting and display of the HTML. Show us your back-end code and then we can help you.
This is what I used to accomplish what you are trying to do.
string-strip-html
It worked pretty well for me.
I now have the search feature working as expected. I would like to thank everyone for their insightful comments. This feedback helped me identify and fix the problem.
OS: Windows Server 2003
IIS: 6.0
Microsoft Index Server
The hit locator tool will only work properly for HTML pages. If you use this tool with a simple TXT file then the results will not be displayed correctly.
Please bear with me as this is not easy to explain. I have a field in a MySQL database that was put there from a form with a textarea input. It seems to me that line breaks are coded as "/n"
When I retrieve the data I can display it on the screen correctly by using the following php lines
$main_article1 = str_replace("\n", "<br />", $row[main_article]);
echo $mainarticle1;
However, now comes the tricky bit. I then want to insert that text into a scroller that uses Javascript.
The code in that script is:
var pausecontent=new Array()
pausecontent[0]='<?php echo $main_article1;?>'
I just get a blank screen.
If I remove the line breaks from the text in the database all works well - the main_article text appears in the scroller as it should - it only stops working when the line breaks are there.
Does anyone know how I can get the line breaks in the database field to go through the PHP script and appear in the scroller text in the Javascript?
I have also tried:
$main_article1 = str_replace("/n>", "%0D%0A", $row[main_article]);
but that does not work either
I hope I have made sense of what I am trying to do.
Many thanks in advance.
Tog
Here is an update
$main_article = 'This is a test<br />This is a test'
the code generated by php within the JS should be:
pausecontent[0]='This is a test<br />This is a test'
(all greyed out) but what I am getting is:
pausecontent[0]='This is a test
This is a test'
and the line break in the JS code is causing it to fail because the text is no longer greyed out after the line break
You can try the nl2br() function
$main_article1 = nl2br($row[main_article]);
also I suggest leaving a space between your code and the closing php tag (?>)
pausecontent[0]='<?php echo $main_article1; ?>'
Got it at last, after too many days headache!
I was looking at the wrong replacement theories
The answer is to use the following line:
$main_article1 = preg_replace("/\r\n|\r|\n/",'<br/>',$row[main_article]);
Now it works perfectly.
Thanks to all for your help.
Regards
Tog
I am trying to parse a HTML code in order to extract all links in it. To avoid unavailable links I remove the commented code that begins with <!-- and ends with --> .Here comes the problem: In the HTML code I may find some JavaScript code, for example:
<html>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (document.images) {
var pic2 = new Image(); // for the inactive image
pic2.src = "pic2.jpg";
var title2 = new Image();
title2.src = "title2.jpg";
}
...
-->
and the weird thing is that the js code is commented but it still works. So, if I remove that code, the result won't be as expected. What should I do in order to identify when I'm facing with unused commented code and when that commented code is functional?
the weird thing is that the js code is commented but it still works
Those aren't comments. Is is just syntax allowed inside script (and style) elements that follows the comment syntax so that browsers which predate script and style don't render the code as text.
What should I do in order to identify when I'm facing with unused commented code and when that commented code is functional?
Write a real HTML parser, following the parsing specification, and then remove any comment nodes from the generated DOM.
As a dirty (but possibly quick) solution, you could just ignore comments inside elements marked as containing CDATA in the HTML 4.01 DTD.
the weird thing is that the js code is commented but it still works
There is nothing weird about it. The comments <!-- --> only work in HTML, not JavaScript. Your above code will still work since you've put these comments within the <script> tags.
The only difference it makes is that if the user has disabled JavaScript on his/her browser, he won't see the code printed on the browser (since HTML will parse those comments in the absence of JavaScript).
You need to comment out the whole <script> block. e.g.
<!-- <script>
...some javascript code...
</script> -->
I'm trying to make a HTML/JS/CSS script that counts the number of days until some birthdays.
Last year, I made one, it still works, I copied and pasted the same script, and changed the names/dates and now it doesn't work.
Working one: http://jsbin.com/iFItOYo/16/edit
Broken one: http://jsbin.com/iFItOYo/14/edit
You made a couple of mistakes:
You forgot the closing bracket at this point:
fatima = new Date(thisYr,2,7)
if (fatima.getTime() < now.getTime()) {
fatima.setYear(nextYr)
} <-- this one is missing
In the beginning you state now = new Date, which should be now = new Date()
You forgot to close the <!-- that you begin in the top of your code
It's quite simple, you are missing the the closing tag of the comment '-->', and thus you get an unexpected end of input error.
Also putting your script inside of a comment is not such a good practice, use cross browser CSS if comments
Also, use indenting, and lower case HTML, with indenting as well.
In addition, your script tag is not valid in any HTML \ XHTML spec.
Hope this helps.
Another issue:
<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT"> which comes after the h3 opening tag is also missing.
Perhaps this question belongs to code review.
You deleted the <script ...> tag right after the opening <body> tag.
There is a lot of mistakes in your code. You should do something to view it clearly so that you can see your mistake easily like indent code, write all in lowercase (both javascript and html), comment and closing code more exactly...
To fix the one not run you must do these 3 points:
1 Like koenp answer, closing this :
falisha = new Date(thisYr,2,20)
if (falisha.getTime() < now.getTime()) {
falisha.setYear(nextYr)
} <== add this bracket
2 Missing the script tag before calling the document write function in body
<H3>The following are the numbers of days until class birthdays (2011-12):
<SCRIPT LANGUAGE=JAVASCRIPT TYPE="TEXT/JAVASCRIPT"> <== add this
3 Wrong variable in this line
if (anahi.getTime() < now.getTime()) {
anihi.setYear(nextYr) <== change it to anahi (of course)
}
This is quite complicated. I'm not able to put this into words directly. So here goes my problem -
I've this short-code generator form built upon WordPress TinyMCE editor which is basically an HTML document. It has two <textarea></textarea> inputs. When user clicks on "Insert short-code", javascript code on this page populates the short-code and inserts it into the editor in WordPress.
Now, if the user inserts something like -
>>>This is an "amazing post"! You can't wait to get your hands on it.<<<
in the one of the textarea, the short-code generates the corresponding attribute as this -
c_text=">>>This is an "amazing post"! You can't wait to get your hands on it.<<<"
This short-code with other attributes is then saved into database by WordPress. When it is retrieved at the front-end, the add_shortcode() function in WordPress messes everything up, which is quite obvious as >,<,',"exist inside c_text
An obvious choice in PHP would be to use htmlentities with ENT_QUOTES, but how to do it in this case? Using the phpjs equivalent function would mean including lot of javascript. How to do this effectively?
UPDATE : I tried using the phpjs equivalent function. It does the conversion properly. But, the quotes are replaced by WordPress.
Example - I put a random string <> <test> <<><<<>><<> ' <"">?sdg##Y^#ASCST##Y^
and did console.log(htmlentities(string,'ENT_QUOTES'));, it logged
<> <test> <<><<<>><<> ' <"">?sdg##Y^#ASCST##Y^
which is correct. But, when I viewed the switched to HTML view of TinyMCE, it showed
<> <test> <<><<<>><<> '
<"">?sdg##Y^#ASCST##Y^
The quotes were replaced by TinyMCE.
I ended up using urlencode function and it worked fine.