Javascript problem
-
I am trying to pop up a window from a link on a web page using the following code:
[head] [script etc etc] function popup(url) { window.open(url,'title','300,300'); } [/script] [/head] [body] [a href='javascript:popup('someurl.html')']blahblah[/a] [/body]
[edit] The colon between javascript and popup is not showing up on this page but it is in the code [/edit] I have only shown the reqd bits so please don't tell me I missed out parts of the page :) Now this works fine except if I use it in an IFrame on IE. On FF etc it works just as I would expect. Does anybody have a clue if this is a security feature of IE? Or what is wrong? Thanks -
I am trying to pop up a window from a link on a web page using the following code:
[head] [script etc etc] function popup(url) { window.open(url,'title','300,300'); } [/script] [/head] [body] [a href='javascript:popup('someurl.html')']blahblah[/a] [/body]
[edit] The colon between javascript and popup is not showing up on this page but it is in the code [/edit] I have only shown the reqd bits so please don't tell me I missed out parts of the page :) Now this works fine except if I use it in an IFrame on IE. On FF etc it works just as I would expect. Does anybody have a clue if this is a security feature of IE? Or what is wrong? ThanksThe problem is that you use the same delimiter for html attributes and javascript strings. The browser thinks that the attribute ends where you think that the string starts. To the browser, it's only this that makes sense of your anchor tag:
[a href='javascript:popup(']blahblah[/a]
This will of course cause an error. If you had error messages enabled in your browser, you would get the error in a popup. Now it only shows up in the status bar. Use quotes for html attributes and apostrophes for javascript strings:[a href="javascript:popup('someurl.html');"]blahblah[/a]
--- b { font-weight: normal; } -
The problem is that you use the same delimiter for html attributes and javascript strings. The browser thinks that the attribute ends where you think that the string starts. To the browser, it's only this that makes sense of your anchor tag:
[a href='javascript:popup(']blahblah[/a]
This will of course cause an error. If you had error messages enabled in your browser, you would get the error in a popup. Now it only shows up in the status bar. Use quotes for html attributes and apostrophes for javascript strings:[a href="javascript:popup('someurl.html');"]blahblah[/a]
--- b { font-weight: normal; } -
Thanks but that was my fault. No the delimeters aren't the same. I just typed them this way in the example code I posted. Sorry.