closing script tag causing issues

New Here ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Hi everyone, 

 

I have a simple piece of code but the cosing script tage on line 20 is causing an issue. As you can see in the image i have attached i am adding a string to the pageContent variable. inside the string i have a script tag containing an alert. the opening tag works perfectly the way it should but the closing script tag has decided to connect to the open script tag on line 6. This shouldnt happen as the closing script tag is inside the string and should not perform as a tag.

 

is there a setting i need to change to fix this or is there a problem with the software ? 

 

scriptTagIssue.jpg

Views

110

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Try:

 

document.lastModified + ' ' ')</script>";

 

I cant test it at the moment but l think you need to close the string within the alert() function

 

These days its easier to use template literals when working with javascript as using + ' blah' + variable can become confusing

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Thanks for the reply.

 

That didn't fix the problem im afraid. The closing script tag on line 20 is part of the string so it shouldn't function as a tag until the function has be activated and the new window opens with the content that the pageContent Variable hold.

 

I can't see any issues with the coding which leaves me to believe that its a programme problem with dreamweaver? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Does it still give you issues if you just use, as a test:

 

"<script>alert('Hello');</script>";

 

Maybe its just because you are missing the closing ; after the alert closing bracket?

 

Im thinking its a code misconfiguration  rather than Dreamweaver related

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

I have just tried altering the alert and it made no difference.

 

I have also just tried commenting out that line and as you can see from the image i have attached the whole line should be commented out but the closing script tag is still active. 

 

Dreamweaver issue.jpg

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Humm ok I'm at a loss.

 

What happens if you get rid of the comment tags <!--        //--> you dont need them.

 

If the code works as intended then l would move on. Linters arent reliable in any editor that l have tried and thats quite a few.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

I'm not a huge fan of Code Linting but try this online JS validation tool:

https://codebeautify.org/jsvalidate

 

Also what happens when you test your script in real browsers, does the script work as intended without errors?

 

Nancy O'Shea, Adobe Product User & Community Professional
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

The code works perfectly if i load it up in a browser with no errors, if however i load it up using the preview in browser it doesnt function how it should because the opening script tag on line 6 is connecting to the closing script tag on line 20 instead of line 33 link its meant to. 

 

I have also loaded the file in other various programmes and the code appears how it should. 

 

Here is an image of the code using visual studio code, which you can see the closing script tag isn't active because its part of the string. 

 

I use alot of adobe programmes and love the look and feel of Dreamweaver so i dont want to use any other programme but there is clearly something not right here?

 

vsCode.jpg

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Optionally, you may turn off Code Linting from Dreamweaver Preferences.

 

But keep in mind that Design View is not a browser.  And Live View is not a real browser either.  It's a Chrome emulation.

 

Real-Time Preview is another issue.  I have disabled RTP from my Preferences because it doesn't play nice with my local testing server.  Old fashioned preview in browser without interference from Adobe's servers is better for my workflow.

 

Nancy O'Shea, Adobe Product User & Community Professional
Alt-Web Design & Publishing ~ Web : Print : Graphics : Media

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

You cant have that line of code where it is, it's being flagged up as an error in the javascript browser console so there is something incorrect with it. Its also showing up as text in the Firefox browser window.

 

From what l can gather its a parsing error, the opening <script> tag of the function pairs itself with the first closing </script> tag it finds.

 

Try escaping the closing script tag on line 20 <\/script> and see what effect that has if anything. Dreamweaver might still not play nicely but the error in the brower javascript console might go away.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

Can you share with me the errors that you have because mine looks like this....

Console errors.jpg

 

Also with the script in dreamweaver not allowing the end closing tag for the script in line 20 to be part of the string you would kind of expect some errors.

 

the simple question is why does dreamweaver stop the </script> being part of the string ? i have tested numours tags and that is the only tag that never works in a string, the open tag works but the closing tag doesnt so why is that. Every other txt editor i use doesnt have this problem as you can see with the visual studio code image i added in earlier comments showing the exact same code just not in dreamweaver and the </script> is part of the string. 

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 18, 2021 Feb 18, 2021

Copy link to clipboard

Copied

LATEST

Thats weird, your browsers console shows no errors.

 

Maybe l got something wrong when l retyped your code but l double checked it. As soon as l removed the line of code containing the script tags the error resolved itself. The strange thing is the error appeared when the page was initially loaded, before the function was evoked by the onclick event.

 

Can you post your  code in the forum, l can then copy it and check it out at some point tomorrow to see if it throws an error.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines