0

This works perfectly in chrome and firefox, and it SHOULD work perfectly in internet explorer.

In fact, if I manually enter a string instead of taking it from the prompt, it works perfectly. The only issue is when I take in the string using 'prompt', and as far as I can tell the value I'm getting from that is a string, just like any other!

    value=prompt("extract","youtube code here");
    el=document.getElementById('textarea');
    //matches=value.match(/.*<embed src=(^>*)>.*/gi);
    item=value.split('<embed src=')[1];
    closeTag=item.indexOf('>');
    if(closeTag>-1)
    {
        item=item.substring(0,closeTag);
    }
    alert(item);
    el.value+=item;
RonLugge
  • 5,086
  • 5
  • 33
  • 61
  • Read the source after load, do you see "embed" getting passed, or "object"? – Eric Hodonsky Jan 25 '12 at 23:04
  • same as http://stackoverflow.com/questions/1453521/javascript-split-doesnt-work-in-ie? – Grace Huang Jan 25 '12 at 23:04
  • I recommend `var startTag = value.indexOf('', startTag);` This code will never fail (your code will fail when the split argument is not given, ie ` – Rob W Jan 25 '12 at 23:05
  • Also, throw an alert/console.log in there to see what value is before you split it... – Eric Hodonsky Jan 25 '12 at 23:05
  • I went into the IE debugger and used some alerts; alert (typeof value) shows that value is supposed to be a string, the debugger doesn't name it a string but it sure looks like it is one. – RonLugge Jan 25 '12 at 23:18

1 Answers1

1

Declare your variables and it seems to work for me in IE7:

var value=prompt("extract","youtube code here");
var el=document.getElementById('textarea');
//matches=value.match(/.*<embed src=(^>*)>.*/gi);
var item=value.split('<embed src=')[1];
var closeTag=item.indexOf('>');
if(closeTag>-1)
{
    item=item.substring(0,closeTag);
}
alert(item);
el.value+=item;
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • 1
    OK, that was an incredibly easy fix... and researching it caused me to discover a critical flaw in my understanding of javascript. I thought adding var made a global variable, turns out it's the opposite... woops! – RonLugge Jan 25 '12 at 23:24