Forum Moderators: open
Here it is:
<script type="text/javascript">
if (window.top.location == http://mydomain.com/page.html?id=x) {
document.write('<style type="text/css">.class1 \{display: none;\} .class2 \{display: block;\}</style>);
}
</script>
The error I'm getting (using FireFox's JS console) is as follows:
missing ) after condition.
It then gives the line with the URL (line 2 here).
Where in the world would another parenthesis go? I've checked with w3schools, did a search here, looked at other javascripts, can't see what I'm doing wrong. Can anyone else spot the error? If so please point it out to me . . . I don't get it at all!
Thanks,
Matthew
if (window.top.location == "http://mydomain.com/page.html?id=x") {
document.write("<style type=\"text/css\">.class1 {display: none;} .class2 {display: block;}</style>");
}
You also had the escape character '\' by the curly bracket '\{' when it should have just been '{'. Use the escape character '\' (without the quotes) to escape the "text\css" so it becomes \"text/css\"
Hope that makes sense.