|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Javascript doesn't work without firebug
Does firebug do something special to force scripts to run? I found this script that unfortunately uses the document.write method. It doesn't run unless I have firebug console enabled. Then it runs fine.
Code:
<script type='text/javascript'>
var spoilernum = 1;
var fbuttons = new Array(); //This is for the buttons we will offer
var fimagepath;
function seturl(url){
fimagepath=url;
}
function fbutton(innercontent, image, alt){
this.innercontent = innercontent; //this is the tag type
this.image = image; //button image
this.alt = alt; // the alt name for the image of the button
}
fbuttons.push(
new fbutton(
'url'
,'link.png'
,'Forum url'
)
);
fbuttons.push(
new fbutton(
'b'
,'bold.png'
,'Forum bold text button'
)
);
fbuttons.push(
new fbutton(
'i'
,'italics.png'
,'Forum italics text button'
)
);
fbuttons.push(
new fbutton(
'image'
,'image.png'
,'Forum image button'
)
);
function makebuttons() {
var i = 0;
document.write('<div id="toolbar">');
for (i = 0; i < 4; i++) {
//console.log('loop number'+i);
//console.log(fimagepath+fbuttons[i].image);
console.log(i);
console.log('<a onclick="askBox(\''+fbuttons[i].innercontent+'\');" href="javascript: markup()"><img class="fbuttons" border="0" src="'+fimagepath+fbuttons[i].image+'" alt="'+fbuttons[i].alt+'"/></a>');
document.write('<a onclick="askBox(\''+fbuttons[i].innercontent+'\');" href="javascript: markup()"><img class="fbuttons" border="0" src="'+fimagepath+'templates/sbsru/images/'+fbuttons[i].image+'" alt="'+fbuttons[i].alt+'"/></a>');
}
document.write('</div>');
}
function countSpoiler() {
var spoilernum = spoilernum + 1;
}
function storeCaret(position) {
if (position.createTextRange){
position.caretPos = document.selection.createRange().duplicate();
}
}
function insertColor(Color) {
surroundText("[color:" + Color + "]" , "[/color]", document.post.body);
document.post.body.focus();
return;
}
function askBox(what) {
if (what == "url") {
var ModText = prompt("Enter URL:", "http://");
if (ModText != null && ModText != '' && ModText != 'http://'){
var LinkText = prompt("Text For Link:","Link");
if (LinkText != null && LinkText != ''){
insertCode(document.post.body, ' ' + LinkText + ' ');
}
}
return;
}
else if (what == "spoiler") {
var SpoilerQ = prompt("Spoiler Question " + spoilernum + ":","");
if (SpoilerQ != null && SpoilerQ != '') {
var SpoilerA = prompt("Spoiler Answer " + spoilernum + ":","");
if (SpoilerA != null && SpoilerA != '') {
insertCode(document.post.body, ' [spoilerq:' + spoilernum + ']' + SpoilerQ + '[/spoilerq] \n'
+ ' [spoilera:' + spoilernum + ']' + SpoilerA + '[/spoilera] ');
countSpoiler();
}
}
}
else if (what == "image") {
var ModText = prompt("Enter URL to Image:", "http://");
if (ModText == null){
return;
}
insertCode(document.post.body, ' [image]' + ModText + '[/image] ');
}
else if (what == "color") {
var ModText = prompt("Enter Color Code:", "#");
if (ModText == null) {
return;
}
insertColor(ModText);
}
else if (what == "list") {
var ModText = "init";
var listoutput = "
Last edited by Kor; 11-30-2009 at 04:21 AM. Reason: wrap the code [code][/code] |
|
#2
|
||||
|
||||
|
Do you have a live test version (link) or the actual html ? The php short tags contain variables that are missing in what you are showing us... that could be part of the problem that we can't see.
Putting line breaks in the middle of code lines is a really bad idea and can cause problems, also you need to take care in what you choose to use for non-ascii symbols - I prefer unicode. var listoutput et al should be something like this... HTML Code:
var listoutput = "\u00B7 \n";
while ( (ModText != null) && (ModText != "") ) {
ModText = prompt("Enter List Item (leave blank to end list).","");
if ( (ModText != null) && (ModText != "") ) {
listoutput = listoutput + "[li]" + ModText + "[/li]";
}
}
listoutput = listoutput + "\n ";
__________________
...but stupidity is terminal. Last edited by opifex; 11-29-2009 at 12:46 AM. |
|
#3
|
|||
|
|||
|
console.log()
you can't use console.log(); without firebug, comment those lines and try it again.
|
|
#4
|
||||
|
||||
|
@Specht08
Nice catch! Would seem that OP copied the source code with Firebug open! ![]() Take out "console.log", do the corrections and it works as much as it can with out the unknown variables.
__________________
...but stupidity is terminal. |
|
#5
|
|||
|
|||
|
I can't believe it
I have to tell you that's amazing. I can understand php failing when you put in extraneous functions, but I guess I just thought Javascript would ignore unknown variables the way css would. I don't know why I thought that since it's retarded, but I did. Thanks so much, that's exactly what was wrong. This isn't as bad as when I misspelled javascript and debugged for hours, but its close.
|
![]() |
| Bookmarks |
| Tags |
| firebug |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|